module LunaPark::Extensions::Wrappable
class-level mixin
@example
class Account extend LunaPark::Extensions::Wrappable attr_reader :type, :id def initialize(type:, id:) @type, @id = type, id end end hash = { type: 'user', id: 42 } acccount = Account.new(hash) Account.new(hash) # => #<Account type='user', id=42> Account.new(acccount) # => raise ArgumentError Account.wrap(hash) # => #<Account type='user', id=42> Account.wrap(acccount) # => #<Account type='user', id=42> Account.wrap(nil) # => nil Account.wrap(true) # => raise 'Account can not wrap TrueClass' Account.wrap(account).eql?(account) # => true
Public Instance Methods
wrap(input)
click to toggle source
# File lib/luna_park/extensions/wrappable.rb, line 33 def wrap(input) case input when self then input when Hash then new(input) when nil then nil else raise Errors::Unwrapable, "#{self} can not wrap #{input.class}" end end