I try to use reflective methods in Ruby and come across behavior that I find in reality.
The following examples seem to work differently in IRB and when ruby script is called:
Example 1:
def myfun; end
p respond_to?(:myfun)
In IRb this says "true", In the script: "false".
Example 2:
ml = methods
def myfun; end
p methods - ml
In IRb, this says [: myfun]. In the script: [].
I found this under 1.8, 1.9 MRI, JRuby 1.5.6 etc., so I assume this is normal.
Why is the difference?
I was sure that the "answer"? this is a way to see if a method is available - why doesn't this work in the above case?
inger source
share