Created
January 12, 2010 23:53
-
-
Save altamic/275770 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Usually | |
undef_method *instance_methods.grep(/^(?!__|object_id)/) | |
def initialize(usual) | |
@usual = usual | |
end | |
def unless(cond, &unusual) | |
if cond | |
unusual.call | |
else | |
@usual.call | |
end | |
end | |
end | |
def usually(&block) | |
Usually.new(block) | |
end | |
usually do | |
p ARGV.inject('I will work with ') { |msg, arg| msg << "#{arg} "} | |
end.unless ARGV.empty? do | |
p 'Provide at least one argument, please.' | |
end | |
# ./usually.rb ciao miao bau => "I will work with ciao miao bau " | |
# ./usually.rb => "Provide at least one argument, please." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment