Using underscors or camel case for variables and functions (def)

I thought you couldn't use camel words in Ruby instead you should use
underscores but I just tried it and it works.

Here is the code I tried.

class Calculator
  def addIt num1,num2
   _num = num1 + num2
    puts _num.to_s
end
  def subIt num1,num2
   _num = num1 - num2
    puts _num.to_s
end

end

add = Calculator.new
sub = Calculator.new

add.addIt(5,5)
sub.subIt(5,2)

Is this valid in Ruby or it works but is not semantically correct?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

It's a style convention, not something Ruby's parser would enforce.

···

On Thu, Apr 14, 2011 at 8:11 PM, Fily Salas <fs_tigre@hotmail.com> wrote:

I thought you couldn't use camel words in Ruby instead you should use
underscores but I just tried it and it works.

--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.

I probably misunderstood this and honestly I don't remember where I read
that.

Thanks a lot for the clarification!

···

--
Posted via http://www.ruby-forum.com/.

I thought you couldn't use camel words in Ruby instead you should use
underscores but I just tried it and it works.

*Should* is the operative word -- not *must*.

Is this valid in Ruby or it works but is not semantically correct?

It works fine. It's just harder to read at a glance than with
underscores for most contexts with method and variable names.

···

On Fri, Apr 15, 2011 at 03:11:48AM +0900, Fily Salas wrote:

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

Fily Salas wrote in post #992819:

I thought you couldn't use camel words in Ruby instead you should use
underscores but I just tried it and it works.

In fact, camel case is recommended for names of constants:

class MyClass #camel case for constants
end

def my_method #snake case
end

my_var = 1 #snake case

···

--
Posted via http://www.ruby-forum.com/\.

Thank you all very much!

···

--
Posted via http://www.ruby-forum.com/.