Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2867 > unrolled thread

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

Started byFily Salas <fs_tigre@hotmail.com>
First post2011-04-14 13:11 -0500
Last post2011-04-14 19:30 -0500
Articles 5 — 3 participants

Back to article view | Back to comp.lang.ruby


Contents

  Using underscors or camel case for variables and functions (def) Fily Salas <fs_tigre@hotmail.com> - 2011-04-14 13:11 -0500
    Re: Using underscors or camel case for variables and functions (def) Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-04-14 13:31 -0500
    Re: Using underscors or camel case for variables and functions (def) Fily Salas <fs_tigre@hotmail.com> - 2011-04-14 14:17 -0500
    Re: Using underscors or camel case for variables and functions (def) 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-14 14:33 -0500
    Re: Using underscors or camel case for variables and functions (def) Fily Salas <fs_tigre@hotmail.com> - 2011-04-14 19:30 -0500

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

FromFily Salas <fs_tigre@hotmail.com>
Date2011-04-14 13:11 -0500
SubjectUsing underscors or camel case for variables and functions (def)
Message-ID<a6023ce7d2b84d9d5ffe9e00030264c9@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.

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/.

[toc] | [next] | [standalone]


#2869

FromPhillip Gawlowski <cmdjackryan@googlemail.com>
Date2011-04-14 13:31 -0500
Message-ID<BANLkTi=S1ZSvSySHVVbxddc94s=869vqiA@mail.gmail.com>
In reply to#2867
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.

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


-- 
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.

[toc] | [prev] | [next] | [standalone]


#2872

FromFily Salas <fs_tigre@hotmail.com>
Date2011-04-14 14:17 -0500
Message-ID<a946502dce624ec194853b09bbc4ad5b@ruby-forum.com>
In reply to#2867
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/.

[toc] | [prev] | [next] | [standalone]


#2874

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-04-14 14:33 -0500
Message-ID<1e684a353314d784a0803ca89187a0bd@ruby-forum.com>
In reply to#2867
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/.

[toc] | [prev] | [next] | [standalone]


#2896

FromFily Salas <fs_tigre@hotmail.com>
Date2011-04-14 19:30 -0500
Message-ID<15dc7702a193a540085ebf344e459c02@ruby-forum.com>
In reply to#2867
Thank you all very much!

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web