And since Object is an ancestor of pretty much everything in ruby,
it's interesting to note that these methods are now defined for
practically everything in ruby:
On 10/27/06, matt neuburg <matt@tidbits.com> wrote:
Dave Rose <bitdoger2@yahoo.com> 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?
But that's just a vagary of how irb works. You couldn't do that in a
real script. m.
···
Jason Merrill <jason.merrill@yale.edu> wrote:
And since Object is an ancestor of pretty much everything in ruby,
it's interesting to note that these methods are now defined for
practically everything in ruby:
Why not? say_hello is now a method of Object, an ancestor of [1,3,5].
Challenge: show us what the error is when it fails.
Hugh
···
On Sat, 28 Oct 2006, matt neuburg wrote:
Jason Merrill <jason.merrill@yale.edu> wrote:
> And since Object is an ancestor of pretty much everything in ruby,
> it's interesting to note that these methods are now defined for
> practically everything in ruby:
>
> irb(main):001:0> def say_hello
> irb(main):002:1> "Hello"
> irb(main):003:1> end
> => nil
> irb(main):004:0> say_hello
> => "Hello"
> irb(main):005:0> [1,3,5].say_hello
> => "Hello"
But that's just a vagary of how irb works. You couldn't do that in a
real script. m.
-:4: private method `howdy' called for [1, 2, 3]:Array (NoMethodError)
m.
···
Hugh Sasse <hgs@dmu.ac.uk> wrote:
On Sat, 28 Oct 2006, matt neuburg wrote:
> Jason Merrill <jason.merrill@yale.edu> wrote:
>
> > And since Object is an ancestor of pretty much everything in ruby,
> > it's interesting to note that these methods are now defined for
> > practically everything in ruby:
> >
> > irb(main):001:0> def say_hello
> > irb(main):002:1> "Hello"
> > irb(main):003:1> end
> > => nil
> > irb(main):004:0> say_hello
> > => "Hello"
> > irb(main):005:0> [1,3,5].say_hello
> > => "Hello"
>
> But that's just a vagary of how irb works. You couldn't do that in a
> real script. m.
Why not? say_hello is now a method of Object, an ancestor of [1,3,5].
Challenge: show us what the error is when it fails.
> > But that's just a vagary of how irb works. You couldn't do that in a
> > real script. m.
>
> Why not? say_hello is now a method of Object, an ancestor of [1,3,5].
> Challenge: show us what the error is when it fails.
matt-neuburgs-imac-g5:~ mattneub$ ruby
def howdy
puts "hi"
end
[1,2,3].howdy
-:4: private method `howdy' called for [1, 2, 3]:Array (NoMethodError)
Thank you. Saw the other post about that being a private method after
posting. I'd completely forgotten about that (as you can tell).
m.
Thanks
Hugh
···
On Sat, 28 Oct 2006, matt neuburg wrote:
Hugh Sasse <hgs@dmu.ac.uk> wrote:
> On Sat, 28 Oct 2006, matt neuburg wrote: