diff --git a/lib/thor/options.rb b/lib/thor/options.rb index c89c8a47d..9c42ca325 100644 --- a/lib/thor/options.rb +++ b/lib/thor/options.rb @@ -28,7 +28,14 @@ def convert_key(key) # Magic predicates. For instance: # options.force? # => !!options['force'] def method_missing(method, *args, &block) - method.to_s =~ /^(\w+)\?$/ ? !!self[$1] : super + method = method.to_s + if method =~ /^(\w+)=$/ + self[$1] = args.first + elsif method =~ /^(\w+)\?$/ + !!self[$1] + else + self[method] + end end end diff --git a/spec/options_spec.rb b/spec/options_spec.rb index 45110368a..4922dbff8 100644 --- a/spec/options_spec.rb +++ b/spec/options_spec.rb @@ -207,6 +207,16 @@ def parse(*args) @hash.foo?.must be_true @hash.nothing?.must be_false end + + it "should map methods to keys: hash.foo => hash[:foo]" do + @hash.foo.must == @hash['foo'] + end + + it "should map setters to keys: hash.foo=bar => hash[:foo] => bar" do + @hash.foo = :bar2 + @hash.foo.must == :bar2 + end + end describe ":numeric type" do