Module: Tutor::Attributes::Default

Included in:
Attribute
Defined in:
lib/tutor/attributes/default.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



3
4
5
# File 'lib/tutor/attributes/default.rb', line 3

def default
  @default
end

Instance Method Details

#default_value_for(object) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tutor/attributes/default.rb', line 5

def default_value_for(object)
  if self.default.class <= Proc
    if self.default.lambda? && self.default.parameters.empty?
      self.default.call
    else
      self.default.call(object)
    end
  else
    self.default
  end
end