From: Walton Hoops Date: 2009-11-21T07:45:17+09:00 Subject: Re: Something like puts > -----Original Message----- > From: marnen@marnen.org [mailto:marnen@marnen.org] > Walton Hoops wrote: > >> > >> > >> I think this has something to do with Modules not mixing in, uh, > class > >> methods. Frankly, I'm not following the arguments. > >> > >> > >> So ... what is the right way to create a function like puts that is > >> known everywhere? > > > > > > Maybe I'm missing something, but I think what you want is to just > > define it in the default global scope: > [...] > > Right. Which actually puts it in Object. I had forgotten about the > syntactic sugar. > Does it? I've heard that before, but this seems to indicate otherwise. irb(main):001:0> def foobar() irb(main):002:1> "Foo" irb(main):003:1> end => nil irb(main):004:0> Object.methods.sort => [:!, :!=, :!~, :<, :<=, :<=>, :==, :===, :=~, :>, :>=, :__id__, :__send__, :a llocate, :ancestors, :autoload, :autoload?, :class, :class_eval, :class_exec, :c lass_variable_defined?, :class_variable_get, :class_variable_set, :class_variabl es, :clone, :const_defined?, :const_get, :const_missing, :const_set, :constants, :define_singleton_method, :display, :dup, :enum_for, :eql?, :equal?, :extend, : freeze, :frozen?, :gem, :hash, :include?, :included_modules, :inspect, :instance _eval, :instance_exec, :instance_method, :instance_methods, :instance_of?, :inst ance_variable_defined?, :instance_variable_get, :instance_variable_set, :instanc e_variables, :is_a?, :kind_of?, :method, :method_defined?, :methods, :module_eva l, :module_exec, :name, :new, :nil?, :object_id, :private_class_method, :private _instance_methods, :private_method_defined?, :private_methods, :protected_instan ce_methods, :protected_method_defined?, :protected_methods, :public_class_method , :public_instance_method, :public_instance_methods, :public_method, :public_met hod_defined?, :public_methods, :public_send, :remove_class_variable, :respond_to ?, :send, :singleton_methods, :superclass, :taint, :tainted?, :tap, :to_enum, :t o_s, :trust, :untaint, :untrust, :untrusted?] irb(main):005:0> o = Object.new => # irb(main):006:0> o.methods.sort => [:!, :!=, :!~, :==, :===, :=~, :__id__, :__send__, :class, :clone, :define_si ngleton_method, :display, :dup, :enum_for, :eql?, :equal?, :extend, :freeze, :fr ozen?, :gem, :hash, :inspect, :instance_eval, :instance_exec, :instance_of?, :in stance_variable_defined?, :instance_variable_get, :instance_variable_set, :insta nce_variables, :is_a?, :kind_of?, :method, :methods, :nil?, :object_id, :private _methods, :protected_methods, :public_method, :public_methods, :public_send, :re spond_to?, :send, :singleton_methods, :taint, :tainted?, :tap, :to_enum, :to_s, :trust, :untaint, :untrust, :untrusted?] irb(main):007:0> Maybe I'm missing something?