Class: KwargModel

Inherits:
Object
  • Object
show all
Defined in:
lib/kdict/kwargmodel.rb

Overview

A convenient class for storing a unique Keyword-Argument Model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, struct, prc = nil) ⇒ KwargModel

Returns a new instance of KwargModel.

Parameters:

  • type (Symbol)

    the typedef of the instance. It can be any one of the typedefs

  • struct

    the structure of the typedef.

  • prc (defaults to: nil)

    an optional Proc that modifies the ‘specificity’ of struct



21
22
23
24
25
# File 'lib/kdict/kwargmodel.rb', line 21

def initialize(type, struct, prc=nil)
  @type = type
  @struct = struct
  @prc = prc if prc
end

Instance Attribute Details

#prcProc (readonly)

Returns a unique Proc if it exists, otherwise nil.

Returns:

  • (Proc)


14
15
16
# File 'lib/kdict/kwargmodel.rb', line 14

def prc
  @prc
end

#structObject (readonly)

Returns the structure of the typedef.



11
12
13
# File 'lib/kdict/kwargmodel.rb', line 11

def struct
  @struct
end

#typetypedef (readonly)

Returns the typdef of the Model.

Returns:

  • (typedef)


7
8
9
# File 'lib/kdict/kwargmodel.rb', line 7

def type
  @type
end

Instance Method Details

#splay[type, struct, prc], [type, struct]

Returns the attributes of the instance as an array.

Examples:

km1 = KwargModel.new(:typeof, Float)
km2 = KwargModel.new(:typeof, Float, Proc.new{true})
km1.splay #=> [:typeof, Float]
km2.splay #=> [:typeof, Float, @prc=#<Proc:[email protected]:20>]

Returns:



36
37
38
# File 'lib/kdict/kwargmodel.rb', line 36

def splay
  @prc ? [@type, @struct, @prc] : [@type, @struct]
end