> From: Ralph Shnelvar [mailto:ralphs / dos32.com] > Newbie question: > > I need/want a function like puts ... that is, a function known > globally. > > I have read the Pickaxe section on mixins and > http://www.ruby-forum.com/topic/68638 and I'm going nuts. > > Specifically I am trying to do > > > module ApplicationHelper > puts "Hearyee ApplicationHelper" > > def at_file_line_msg(file, line, msg) > file + " @ " + line.to_s + ":" + msg > end > > puts at_file_line_msg(__FILE__, __LINE__, "") > end > > The > puts at_file_line_msg(__FILE__, __LINE__, "") > generates the right output. > > When I attempt to mixin ApplicationHelper into a classand then attempt > to call > puts at_file_line_msg(__FILE__, __LINE__, "") > I get a "module not defined" error. > > > 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: irb(main):002:0> def foo #our global function irb(main):003:1> 'bar' irb(main):004:1> end => nil irb(main):011:0> class Blah irb(main):012:1> def b irb(main):013:2> foo #Our function defined earlier irb(main):014:2> end irb(main):015:1> end => nil irb(main):016:0> b=Blah.new => #<Blah:0x2d58d20> irb(main):017:0> b.b => "bar" irb(main):018:0>