[Rubycocoa-devel 794] Re: Minor issue with self.privateMethod

Zurück zum Archiv-Index

Laurent Sansonetti lsans****@apple*****
Thu Mar 1 01:43:44 JST 2007


Oh Brian is right, this is not a Ruby bug in the sense that trying to  
call a private method with "self" as the receiver doesn't seem valid.  
And of course, in #method_missing we try to resolve an Objective-C  
selector and this fails. We may want to raise a ```NoMethodError:  
private method `XXX' called for #YYY''' instead.

Laurent

On Feb 28, 2007, at 5:01 PM, brian hammond wrote:

> irb(main):001:0> class A
> irb(main):002:1> def initialize
> irb(main):003:2>   self.foo
> irb(main):004:2> end
> irb(main):005:1> private
> irb(main):006:1> def foo
> irb(main):007:2>   puts "hi"
> irb(main):008:2> end
> irb(main):009:1> end
> => nil
> irb(main):010:0> A.new
> NoMethodError: private method `foo' called for #<A:0x7e02c>
>        from (irb):3:in `initialize'
>        from (irb):10:in `new'
>        from (irb):10
>        from :0
>
> irb(main):011:0> class A
> irb(main):012:1> def initialize
> irb(main):013:2>   foo
> irb(main):014:2> end
> irb(main):015:1> private
> irb(main):016:1> def foo
> irb(main):017:2>   puts "hi"
> irb(main):018:2> end
> irb(main):019:1> end
> => nil
> irb(main):020:0> A.new
> hi
>
>
> - Brian
>
> ----- Original Message ----
> From: Jacob Wallström <jacob****@ghost*****>
> To: rubyc****@lists*****
> Sent: Wednesday, February 28, 2007 10:53:30 AM
> Subject: [Rubycocoa-devel 791] Minor issue with self.privateMethod
>
> I discovered that the following won't work using Rubycocoa-unstable
> (revision 1600).
>
> class MyClass < OSX::NSObject
>
>    def publicMethod
>        self.privateMethod # gives error method not found
>        privateMethod        # works
>    end
>
>    private
>
>    def privateMethod
>    end
> end
>
> Since it is valid to call private methods in ruby using the self
> notation, I think it should work in RubyCocoa too.
>
> Best regards,
> Jacob Wallström
> http://ghostparksoftware.com
>
>
> _______________________________________________
> Rubycocoa-devel mailing list
> Rubyc****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel
>
>
>
>
>
>
> ____________________________________________________________________________________
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail arrives.
> http://tools.search.yahoo.com/toolbar/features/mail/
> _______________________________________________
> Rubycocoa-devel mailing list
> Rubyc****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/rubycocoa-devel




More information about the Rubycocoa-devel mailing list
Zurück zum Archiv-Index