I am a ruby beginner. From the book, I know that ruby method name should start with a lowercase letter ( or underscore). But I found different scenarios:
if a method is defined outside a class, it can only begin with lowercase letter, Ruby will complain error if you try to define a method which begin with uppercase letter, for example:
define sayHi puts "Hello" end sayHi # => Hello
but, the following code is not working:
define SayHi puts "Hello" end SayHi it will produce error: :in `': uninitialized constant SayHi (NameError)
- If a method is defined inside a class, then it can begin with uppercase letter:
class Test def SayHi puts "hello" end end t = Test.new t.SayHi # => hello
Does anyone know why #1 does not work while #2 work? What are the exact rules the ruby method name?