rails/rails — pull request #11262 by phstc (2013-07-03 00:37:31+00:00)
Title: Treats hash keys as methods (getter/setter) #delegate

I would like to propose to treat Hash keys as methods in the method delegation through `delegate`.

Example:

```ruby
class Order < ActiveRecord::Base
serialize :response

delegate :code, :message, to: :response

def place
# ...
response = json_response
end
end

Order.new # ...
Order.place
Order.code
# => 200
Order.message
# => Order created
```

Currently I have to write boilerplate code to expose these keys as methods.

```ruby
class Order < ActiveRecord::Base
serialize :response

delegate :code, :message, to: :response_data

def place
# ...
response = json_response
end

def code; response[:code]; end
def message; response[:message]; end
end
```