From: Logan Capaldo Date: 2006-02-09T09:05:27+09:00 Subject: Re: how to create singleton methods in script On Feb 8, 2006, at 6:58 PM, charlie bowman wrote: > Here is a simplified version of a little timekeeper app that I've been > using to learn ruby with. The TimeKeeper class is a class I created > also. I want to add a method to the script that displays some text > if a > bad action occurs but I can't get it to work. I don't know how to > tell > the script to use the method ( or function as I would call it in > perl). > This is my error. > > undefined method `display_bad_action' for # > (NoMethodError > > usr/bin/ruby > > require 'TimeKeeper' > > ## create the TimeKeeper object > time_keeper = TimeKeeper.new(ARGV) # Ok > puts time_keeper.display_bad_action(time_keeper.action) # Oops, > this method doesn't exist, YET > > ## method to display messages regarding bad action (ie can't logout > when > on break) > def time_keeper.display_bad_action(action) # NOW, I know how to > call this method. > [code omitted] > end > try time_keeper = TimeKeeper.new(ARGV) then def time_keeper.display_bad_action then foollow that with any code that might follow it. > > -- > Posted via http://www.ruby-forum.com/. >