Module: Solid::Model::Access

Defined in:
lib/solid/model/access.rb

Overview

Instance Method Summary collapse

Instance Method Details

#slice(*methods) ⇒ Object

Returns a hash of the given methods with their names as keys and returned values as values.

person = Person.new(id: 1, name: "bob")
person.slice(:id, :name)
=> { "id" => 1, "name" => "bob" }


13
14
15
# File 'lib/solid/model/access.rb', line 13

def slice(*methods)
  methods.flatten.index_with { |method| public_send(method) }.with_indifferent_access
end

#values_at(*methods) ⇒ Object

Returns an array of the values returned by the given methods.

person = Person.new(id: 1, name: "bob")
person.values_at(:id, :name)
=> [1, "bob"]


22
23
24
# File 'lib/solid/model/access.rb', line 22

def values_at(*methods)
  methods.flatten.map! { |method| public_send(method) }
end