Class: Object

Inherits:
BasicObject
Defined in:
lib/r_kit/utility/object_extend.rb,
lib/r_kit/decoration/object_extend.rb

Instance Method Summary collapse

Instance Method Details

#fetch(statement = nil, value = nil, &block) ⇒ Object

TODO: return self if statement (or block), else, return “value”



10
11
12
# File 'lib/r_kit/utility/object_extend.rb', line 10

def fetch statement = nil, value = nil, &block
  state(statement, &block) ? self : value
end

#need_decoration?Boolean

Returns:

  • (Boolean)


3
# File 'lib/r_kit/decoration/object_extend.rb', line 3

def need_decoration?() false end

#reverse_fetch(statement = nil, value = nil, &block) ⇒ Object



14
15
16
# File 'lib/r_kit/utility/object_extend.rb', line 14

def reverse_fetch statement = nil, value = nil, &block
  !state(statement, &block) ? self : value
end

#state(statement = nil, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/r_kit/utility/object_extend.rb', line 18

def state statement = nil, &block
  if statement
    case self
    when statement
      true
    else
      false
    end
  elsif block_given?
    !!block.call(self)
  else
    raise ArgumentError, 'Must send either "statement" or "&block" argument.'
  end
end