C
Chris Hall
i'm having an issue where i need to compare 2 objects by comparing a
Proc which is stored in an instance var. however, everything i have
tried results in a false comparison.
simple example:
class Test
attr :action
def initialize(&block)
@action = block_given? ? block : nil
end
def ==(obj)
if obj.is_a?(Test)
return @action.eql?(obj.action)
end
end
end
t1 = Test.new { puts "hello" }
t2 = Test.new { puts "hello" }
puts "comp: #{t1 == t2}"
puts "t1 action: #{t1.action}"
puts "t2 action: #{t2.action}"
output:
comp: false
t1 action: #<Proc:0x00025134@eql_test.rb:15>
t2 action: #<Proc:0x0002501c@eql_test.rb:16>
when the objects are created, i use the same block of code when i create
each instance, however, it obvious that from the comparison output they
aren't the same. my question, how do i get the comparison i'm looking
for?
Proc which is stored in an instance var. however, everything i have
tried results in a false comparison.
simple example:
class Test
attr :action
def initialize(&block)
@action = block_given? ? block : nil
end
def ==(obj)
if obj.is_a?(Test)
return @action.eql?(obj.action)
end
end
end
t1 = Test.new { puts "hello" }
t2 = Test.new { puts "hello" }
puts "comp: #{t1 == t2}"
puts "t1 action: #{t1.action}"
puts "t2 action: #{t2.action}"
output:
comp: false
t1 action: #<Proc:0x00025134@eql_test.rb:15>
t2 action: #<Proc:0x0002501c@eql_test.rb:16>
when the objects are created, i use the same block of code when i create
each instance, however, it obvious that from the comparison output they
aren't the same. my question, how do i get the comparison i'm looking
for?