ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Differences between irb and ruby.
by Ezra Zygmuntowicz other posts by this author
Jun 30 2006 9:30PM messages near this date
Re: Differences between irb and ruby. | Re: Differences between irb and ruby.
Hi-

On Jun 30, 2006, at 9:19 PM, Minkoo Seo wrote:

>  Hi Ezra.
> 
>  You've got it wrong. The point is that though a method that is defined
>  outside of any class becomes automatically part of Object, it can't be
>  called with exact receiver because the method is *private*.
> 
>  In other words,
> 
>  # foo is private method of Object
>  def foo
>   ..
>  end
> 
>  class Bar; end
> 
>  # This is okay, because I'm calling self.foo and we do not
>  # need to state self as receiver.
>  foo
> 
>  # This is completely wrong. Private method can't be called
>  # with exact receiver.
>  Bar.new.foo
> 
>  Hope this helps.
> 
>  Sincerely,
>  Minkoo Seo
> 


My irb disagrees with you

irb(main):012:0>  def foo
irb(main):013:1>  puts 'foo'
irb(main):014:1>  end
=>  nil
irb(main):015:0>  class Bar
irb(main):016:1>  end
=>  nil
irb(main):017:0>  Bar.new.foo
foo
=>  nil
irb(main):018:0>  Object.private_methods.grep /foo/
=>  []
irb(main):019:0>  Object.instance_methods.grep /foo/
=>  ["foo"]
irb(main):020:0>  Bar.instance_methods.grep /foo/
=>  ["foo"]
irb(main):021:0>  Bar.private_methods.grep /foo/
=>  []

But I understand that in a normal ruby script methods def'ed outside  
of a class definition becore private methods of Object but its not  
the case in irb.

-Ezra
Thread:
Minkoo Seo
Ezra Zygmuntowicz
Minkoo Seo
Ezra Zygmuntowicz
Austin Ziegler
Minkoo Seo
Logan Capaldo
Mauricio Fernandez

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved