Hi,
I've discovered some strange behaviour in Interactive Ruby shell (IRB) I
cann't explain myself. It manifests only with Wirble enhacement with
colorization enabled.
Class.methods.uniq.sort
=> [:!, :!, :!, :, :, :=>, :, :, :, :, :, :__id__, :__send__, :allocate,
:ancestors, :autoload, :autoload?, :class, :class_eval, :class_exec,
:class_variable_defined?, :class_variable_get, :class_variable_set,
:class_variables, :clone, :const_defined?, :const_get, :const_missing,
:const_set, :constants, :define_singleton_method, :display, :dup,
:enum_for, :eql?, :equal?, :extend, :freeze, :frozen?, :hash, :include?,
:included_modules, :initialize_clone, :initialize_dup, :inspect,
:instance_eval, :instance_exec, :instance_method, :instance_methods,
:instance_of?, :instance_variable_defined?, :instance_variable_get,
:instance_variable_set, :instance_variables, :is_a?, :kind_of?, :method,
:method_defined?, :methods, :module_eval, :module_exec, :name, :nesting,
:new, :nil?, :object_id, :po, :poc, :pretty_inspect, :pretty_print,
:pretty_print_cycle, :pretty_print_inspect,
:pretty_print_instance_variables, :private_class_method,
:private_instance_methods, :private_method_defined?, :private_methods,
:protected_instance_methods, :protected_method_defined?,
:protected_methods, :public_class_method, :public_instance_method,
:public_instance_methods, :public_method, :public_method_defined?,
:public_methods, :public_send, :remove_class_variable, :respond_to?,
:respond_to_missing?, :ri, :send, :singleton_class, :singleton_methods,
:superclass, :taint, :tainted?, :tap, :to_enum, :to_s, :trust, :untaint,
:untrust, :untrusted?]
Class.methods.class
=> Array
defined? Class.methods
=> "method"
Class.methods.uniq.sort[0].class
=> Symbol
Class.methods.uniq.sort[1].class
=> Symbol
defined? (Class.methods.uniq.sort[0])
=> "method"
defined? (Class.methods.uniq.sort[1])
=> "method"
Class.methods.uniq.sort[0] == Class.methods.uniq.sort[1]
=> false
How can be the same symbols(names) different ? Can somebody explain ?
If I define my own array of symbols, method 'uniq' works as expected,
because the same symbols are discarded.
[:one,:two,:three,:two,:four,:one].uniq
=> [:one, :two, :three, :four]
Can this be explained as a correct Ruby's behaviour or did I missed
something ?
Thanks.
David
···
--
Posted via http://www.ruby-forum.com/.