Hi, the following code fails: module Module1 module Module2 end end def Module1::Module2.hello puts "HELLO" end syntax error, unexpected keyword_end, expecting $end But I can do: def Module1.hello puts "HELLO" end why does the former fail? Any trink? Thanks a lot.
on 2012-08-03 17:14
on 2012-08-04 04:09
I know one way to define module method
module Module1::Module2
def self.hello
puts 'HELLO'
end
end
On Fri, Aug 3, 2012 at 11:13 PM, Iñaki Baz Castillo <ibc@aliax.net>
wrote:
> end
>
> why does the former fail? Any trink?
>
> Thanks a lot.
>
> --
> Iñaki Baz Castillo
> <ibc@aliax.net>
>
>
--
William Herry
====================
WilliamHerryChina@Gmail.com
on 2012-08-04 20:10
2012/8/4 William Herry <william.herry.china@gmail.com>: > I know one way to define module method > > module Module1::Module2 > def self.hello > puts 'HELLO' > end > end Sure, but what I ask is why this works: def Module1.hello ; end end this fails: def Module1::Module2.hello ; end
on 2012-08-04 20:33
Because it's how it defined in ruby syntax: def class; dot or color; method name You can't use nesting in it. So it's limited on a lexer level.
on 2012-08-04 20:46
2012/8/4 Sigurd <cu9ypd@gmail.com>: > Because it's how it defined in ruby syntax: def class; dot or color; method name > You can't use nesting in it. So it's limited on a lexer level. Thanks for the clarification.
on 2012-08-04 22:06
On Sat, Aug 4, 2012 at 7:07 PM, Iaki Baz Castillo <ibc@aliax.net> wrote: > > <ibc@aliax.net> > As Sigurd has pointed out, it's a syntax precedence thing. You can do this however: def (Module1::Module2).hello puts "HELLO" end Regards, Sean
on 2012-08-04 22:19
2012/8/4 Sean O'Halpin <sean.ohalpin@gmail.com>: > As Sigurd has pointed out, it's a syntax precedence thing. You can do > this however: > > def (Module1::Module2).hello > puts "HELLO" > end Great! thanks a lot.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.