2016-05-24 17:33:41 -04:00
|
|
|
* Introduce Module#delegate_missing_to.
|
2016-02-27 12:23:42 -05:00
|
|
|
|
|
|
|
When building a decorator, a common pattern emerges:
|
|
|
|
|
|
|
|
class Partition
|
|
|
|
def initialize(first_event)
|
|
|
|
@events = [ first_event ]
|
|
|
|
end
|
|
|
|
|
|
|
|
def people
|
|
|
|
if @events.first.detail.people.any?
|
|
|
|
@events.collect { |e| Array(e.detail.people) }.flatten.uniq
|
|
|
|
else
|
|
|
|
@events.collect(&:creator).uniq
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def respond_to_missing?(name, include_private = false)
|
|
|
|
@events.respond_to?(name, include_private)
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(method, *args, &block)
|
|
|
|
@events.send(method, *args, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
With `Module#delegate_missing_to`, the above is condensed to:
|
|
|
|
|
|
|
|
class Partition
|
|
|
|
delegate_missing_to :@events
|
|
|
|
|
|
|
|
def initialize(first_event)
|
|
|
|
@events = [ first_event ]
|
|
|
|
end
|
|
|
|
|
|
|
|
def people
|
|
|
|
if @events.first.detail.people.any?
|
|
|
|
@events.collect { |e| Array(e.detail.people) }.flatten.uniq
|
|
|
|
else
|
|
|
|
@events.collect(&:creator).uniq
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
*Genadi Samokovarov*, *DHH*
|
|
|
|
|
2016-05-13 20:43:48 -04:00
|
|
|
* Rescuable: If a handler doesn't match the exception, check for handlers
|
|
|
|
matching the exception's cause.
|
|
|
|
|
|
|
|
*Jeremy Daer*
|
2016-05-06 17:54:40 -04:00
|
|
|
|
2016-05-10 00:07:09 -04:00
|
|
|
Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activesupport/CHANGELOG.md) for previous changes.
|