Kalman Noel
2/20/2007 9:58:00 AM
Wolfgang Nádasi-Donner:
> I am confused about "Array#uniq".
Although you already have the answer on dclr, for this list's archives:
Strings are handled in a special way, as shown here:
definitions = lambda do
alias :org_equal_op :==
def ==(other)
puts '== called'
org_equal_op(other)
end
alias :org_hash :hash
def hash
puts 'hash called'
org_hash
end
alias :org_eql? :eql?
def eql?(other)
puts 'eql? called'
org_eql?(other)
end
alias :org_equal? :equal?
def equal?(other)
puts 'equal? called'
org_equal?(other)
end
end
String.module_eval &definitions
Regexp.module_eval &definitions
puts 'Regexp:'
p [ /a/, /b/, /a/, /c/, /b/ ].uniq
puts 'String:'
p %w(a b a c b).uniq
puts "\nRegards, Kalman"
__END__
Output:
Regexp:
hash called
hash called
hash called
eql? called
hash called
hash called
eql? called
hash called
hash called
hash called
hash called
hash called
[/a/, /b/, /c/]
String:
["a", "b", "c"]
Regards, Kalman