Class: TypeConstraints::Meta

Inherits:
Object
  • Object
show all
Defined in:
lib/type_constraints/meta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Meta

Returns a new instance of Meta.



5
6
7
8
9
# File 'lib/type_constraints/meta.rb', line 5

def initialize(args={})
  @name       = args[:name]
  @parent     = args[:parent]
  @constraint = args[:constraint]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/type_constraints/meta.rb', line 4

def name
  @name
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/type_constraints/meta.rb', line 4

def parent
  @parent
end

Instance Method Details

#check?(val) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/type_constraints/meta.rb', line 16

def check?(val)
  if !parent.nil? && !parent.check?(val)
    return false
  end
  constraint.call(val)
end

#constraint(v = nil) ⇒ Object



11
12
13
14
# File 'lib/type_constraints/meta.rb', line 11

def constraint(v=nil)
  @constraint = v if !v.nil?
  @constraint
end