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.
···
--
Iñaki Baz Castillo
<ibc@aliax.net>
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:
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.
--
Iñaki Baz Castillo
<ibc@aliax.net>
--
William Herry
WilliamHerryChina@Gmail.com
Sure, but what I ask is why this works:
def Module1.hello ; end
end this fails:
def Module1::Module2.hello ; end
···
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
--
Iñaki Baz Castillo
<ibc@aliax.net>
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 Aug 4, 2012, at 9:07 PM, Iñaki Baz Castillo wrote:
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
--
Iñaki Baz Castillo
<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 Sat, Aug 4, 2012 at 7:07 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
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
--
Iñaki Baz Castillo
<ibc@aliax.net>
Thanks for the clarification.
···
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.
--
Iñaki Baz Castillo
<ibc@aliax.net>