Ruby 2.3 has a method to_proc for a Hash and it work's in a diffrent way.
It looks like this:
my_hash = {
a: 1, b: 2, c: 3, d: 4, e: 5, f: 6
}
[:e, :a, :b, :f, :c, :d].map(&my_hash)
# => [5, 1, 2, 6, 3, 4]
Am Mittwoch, 24. Februar 2016 06:25:44 UTC+1 schrieb Ivan Denysov:
>
> class Hash
> def to_proc
> proc { |o| all? { |k, v| v === o[k] } }
> end
> end
>
> This would allow to use Hash as a proc argument for methods in
> *Enumerable* module:
>
> array = [{ key: "a" }, { key: "2aZ" }, { key: 12 }]
>
>
> array.find(&{key: /Z/}) # => { key: "2aZ" }
> array.select(&{key: 1..20}) # => [{ key: 12}]
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.