I'm trying to use reflective methods in Ruby, and running into a behavior that I find really surpising.
The following examples seems to work differently in IRB and when called a ruby script:
Example 1:
def myfun; end
p respond_to?(:myfun)
In IRb, this says 'true', In script: 'false'.
Example 2:
ml = methods
def myfun; end
p methods - ml
In IRb, this says [:myfun]. In 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 pretty sure 'respond_to?' is the way to see if a method is available - why is that not working in the above case?