From: Marc Heiler Date: 2012-10-24T22:20:49+09:00 Subject: Re: Calling a method foo() or an object foo.method_call_here - both Hi, Your example unfortunately requires the leading name of the object. This is not what I want, because it would require additional typing effort. For instance: h.hello 'Hi' # 'Hi' hello # ^^^ This would be ok. h.hello 'Hi' # 'Hi' h.hello # 'Hallo world!' ^^^ This would require a "h." to query, and thus would not be an advantage over the current solution I have. (I already use this in my current code, I am really wanting to get rid of this, if possible.) > However, your idea *is* possible. You could define your > own Function class that takes a proc and calls it using > the predefined default values. > But then you'd basically have to write your own > variant of Ruby's method calling logic. The > information about the parameter types (required, > optional, other) of a proc is accessible via > Proc#parameters. > The question is if this is worth the effort. Hmm. If I could use the above syntax, then it might be worth the effort. I currently "solve" this like this: class Foo # code inside it... about 6 lines of code. end def foo end Foo.set_default_value 'bla' # now all calls to foo() method have this value class Bar # code inside it... about 6 lines of code. end def bar end Boo.set_default_value 'bla' # now all calls to bar() method have this value This already works. What I don't like is that I need to call it upcased. I'd really love to be able to use this downcased in any way. You write that it may be possible, but is it really possible? I was thinking that, if I would have something like: foo.set_default_value I'd need to call the method anyway, and that method could then return a specific object, perhaps stored in a global variable or something. But how would it then know what to do, especially if the method in question is unbound, like so in "free form": def foo(input) puts input # return Foo.new here, unless it already exists end But somehow, the method would have to know if it would be called like so: foo() foo vs. so: foo.call_a_method_here # but this would actually mean: foo().call_a_method_here() Unless I am mistaken, with this syntax: foo.call_a_method_here There is absolutely no way to call a foo() method, and call on an object on it, IF we also want to retain the foo() method standalone, without message check right? In other words: foo foo.call_a_method Can never work together or? I am fine if foo would return anything else, I only need to tap into the object in question if the syntax call would be something like: foo.call_a_method here -- Posted via http://www.ruby-forum.com/.