def display_method(NM)
puts “I am in Display Method #{NM}”
end
for I in 0…5
display_method “Testing Ruby MEthod”
if I<2
break
end
end
Hi, I am new learner in ruby, and getting error say “formal argument
cannot be a constant” Can any one help me pls?
Thanks for your help in advance.
In Ruby, variable names start with lower-case letters and constants
(including class names) start with upper-case letters. You are using an
upper-case I for your loop variable, which doesn’t follow these rules.
Randy
On Mon, Feb 6, 2012 at 7:30 PM, Hasmukh P. [email protected]
wrote:
Hi, I am new learner in ruby, and getting error say “formal argument
cannot be a constant” Can any one help me pls?
In Ruby, constants start with upper case letter, the error message
tells you that you cannot have a constant as a parameter to the
method. Downcase it:
def display_method(nm)
puts “I am in Display Method #{nm}”
end
and you should be good to go.
Jesus.
Randy C. wrote in post #1044376:
In Ruby, variable names start with lower-case letters and constants
(including class names) start with upper-case letters. You are using an
upper-case I for your loop variable, which doesn’t follow these rules.
Randy
Thanks Randy. It works