Skip to content

Instantly share code, notes, and snippets.

@velppa
Last active December 20, 2015 10:38
Show Gist options
  • Save velppa/6116593 to your computer and use it in GitHub Desktop.
Save velppa/6116593 to your computer and use it in GitHub Desktop.
require 'trollop'
class Test
attr_reader :a
attr_reader :opts
def initialize
@a = 'qwer'
@opts = Trollop::options do
opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
opt :num_limbs, "Number of limbs", :default => 4 # an integer --num-limbs <i>, defaulting to 4
opt :qwer, 'Test', :default => "This is a - #{@a}"
opt :num_thumbs, "Number of thumbs", :type => :int # an integer --num-thumbs <i>, defaulting to nil
end
end
end
a = Test.new()
puts("this is #{a.a} and it's good")
## if called with no arguments
p a.opts # => { :monkey => false, :goat => true, :num_limbs => 4, :num_thumbs => nil }
@velppa
Copy link
Author

velppa commented Jul 30, 2013

Не видит @A на 12-й строке

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment