Ruby again: Any string can be a method name
May 9th, 2007
Mattz wrote that he designed Ruby with the intent of least surprise.
While tooling around with Liquid Templates I was surprised to learn that a method can begin with a capital letter. What a pleasant surprise. A little experimentation in irb provided more insight into allowable method names. Check it out.
irb(main):005:0> self.class.send :define_method, "Is this a funny name for a method?" do
irb(main):006:1* "Yes, but Ruby doesn't care."
irb(main):007:1> end
=> #<Proc:0xb7cf1900@(irb):5>
irb(main):008:0> self.send "Is this a funny name for a method?"
=> "Yes, but Ruby doesn't care."
Crazy!
Your Response