Eero Saynatkari
10/27/2006 5:12:00 PM
On 2006.10.28 01:10, Dave Rose wrote:
> what class does a classless independent method belong too?
> another words if i just make an new irb session and type:
>
> def widget(tidbit)
> tidbit
> end
>
> a=1.0
> puts widget(a)
>
> b='string'
>
> puts widget(b)
>
> what class will the widget method belong too?
Ruby can tell you.
def widget
# ...
end
p method('widget') # => #<Method: Object#widget>
p Object.methods.include? 'widget' # => true
p Object.ancestors # => [Object, Kernel]
p Kernel.methods.include? 'widget' # => true