New Ruby User

Hi,

I am teaching myself ruby. I would like to be involved in forum. For
now, I’m trying to write a prgram to compare 2 numbers (9,3) using
classes and objects. It is not working.

class Compare
def initialize (int_a, int_b)
@int_a = int_a
@int_b = int_b
end

def compare(int_a, int_b)
if (int_a> int_b)
return int_a
else
return int_b
end

end

2_ints = Compare.new(9, 3)
2_ints.compare

Timothy Wi wrote in post #1147020:

Hi,

Because you are not following the local variable naming semantics. It
shouldn’t start with numbers. To know more about this, read -
http://www.ruby-doc.org/core-2.1.0/doc/syntax/assignment_rdoc.html#label-Local+Variable+Names

2_ints = Compare.new(9, 3)
2_ints.compare

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs