Skip to content

Instantly share code, notes, and snippets.

@altamic
Created January 12, 2010 23:53
Show Gist options
  • Save altamic/275770 to your computer and use it in GitHub Desktop.
Save altamic/275770 to your computer and use it in GitHub Desktop.
#!/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