Standard methods available on all objects in Ruby
Archive - Originally posted on "The Horse's Mouth" - 2012-06-23 12:40:38 - Graham EllisThere are a lot of things I can do with any object in Ruby - there's a whole package deal of methods available to me by just defining and creating an object:
irb(main):003:0> class Thing
irb(main):004:1> end
=> nil
irb(main):005:0> widget = Thing.new
=> #<Thing:0x98c1e74>
irb(main):006:0> widget.methods
=> [:nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup,
:initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect,
:methods, :singleton_methods, :protected_methods, :private_methods, :public_methods,
:instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?,
:instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend,
:display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==,
:equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
irb(main):007:0>
Question from last weeks course - But what do all of these DO?
Answer - I've added a list which describes most of them [here].