T
Tom Reilly
class Tl
def initialize(a,b)
@a = a
@b = b
end
def to_s
"#{@a} #{@b}"
end
def <=>(tlr)
if @a > tlr.@a
1
elsif
@a == tlr.@a
0
else
-1
end
end
end
aa = Tl.new("tom","reilly")
ab = Tl.new("jack","charity")
r = aa <=> ab
p r
--------------------------
tmp.rb:12: warning: useless use of a variable in void context
tmp.rb:14: syntax error
tmp.rb:15: syntax error
tmp.rb:15: warning: useless use of a variable in void context
tmp.rb:19: warning: else without rescue is useless
tmp.rb:22: syntax error
Considering I've been using Ruby for a couple of years, I've been
totally frustrated
making this bit of code work.
Help!
Thanks
def initialize(a,b)
@a = a
@b = b
end
def to_s
"#{@a} #{@b}"
end
def <=>(tlr)
if @a > tlr.@a
1
elsif
@a == tlr.@a
0
else
-1
end
end
end
aa = Tl.new("tom","reilly")
ab = Tl.new("jack","charity")
r = aa <=> ab
p r
--------------------------
tmp.rb:12: syntax errorruby -cw tmp.rb
tmp.rb:12: warning: useless use of a variable in void context
tmp.rb:14: syntax error
tmp.rb:15: syntax error
tmp.rb:15: warning: useless use of a variable in void context
tmp.rb:19: warning: else without rescue is useless
tmp.rb:22: syntax error
Exit code: 1
Considering I've been using Ruby for a couple of years, I've been
totally frustrated
making this bit of code work.
Help!
Thanks