Class: Cmdopt::Options
- Inherits:
-
Object
- Object
- Cmdopt::Options
- Defined in:
- lib/cmdopt.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, val) ⇒ Object
-
#initialize(dict = nil) ⇒ Options
constructor
A new instance of Options.
- #inspect ⇒ Object
Constructor Details
#initialize(dict = nil) ⇒ Options
Returns a new instance of Options.
229 230 231 232 233 234 235 236 |
# File 'lib/cmdopt.rb', line 229 def initialize(dict=nil) if dict dict.each {|k, v| instance_variable_set("@#{k}", v) } (class << self; self; end).class_eval do attr_accessor *dict.keys end end end |
Instance Method Details
#[](name) ⇒ Object
238 239 240 |
# File 'lib/cmdopt.rb', line 238 def [](name) instance_variable_get("@#{name}") end |
#[]=(name, val) ⇒ Object
242 243 244 |
# File 'lib/cmdopt.rb', line 242 def []=(name, val) instance_variable_set("@#{name}", val) end |
#inspect ⇒ Object
246 247 248 249 250 251 |
# File 'lib/cmdopt.rb', line 246 def inspect s = self.instance_variables.sort.collect {|name| "#{name[1..-1]}=#{instance_variable_get(name).inspect}" }.join(', ') return "<Cmdopt::Options #{s}>" end |