Class: Wood::Types::Array

Inherits:
CompoundType show all
Defined in:
lib/wood/types.rb

Instance Attribute Summary collapse

Attributes inherited from CompoundType

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CompoundType

#zero_value

Methods included from TypeMatching

included

Constructor Details

#initialize(type, size = nil) ⇒ Array

Returns a new instance of Array.



58
59
60
61
# File 'lib/wood/types.rb', line 58

def initialize(type, size = nil)
  super(type)
  @size = size
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



57
58
59
# File 'lib/wood/types.rb', line 57

def size
  @size
end

Class Method Details

.[](*options) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/wood/types.rb', line 47

def self.[](*options)
  case options.first
  when Hash
    options = options.first
    new(options[:type], options[:size])
  else
    new(*options)
  end
end

Instance Method Details

#==(other) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/wood/types.rb', line 71

def == other
  case other
  when Array
    if size && other.size
      return type == other.type && size == other.size
    else
      return type == other.type
    end
  else
    return false
  end
end

#===(other) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/wood/types.rb', line 84

def === other
  case other
  when Array
    if size && other.size
      return type === other.type && size === other.size
    else
      return type === other.type
    end
  else
    return false
  end
end

#builtin?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/wood/types.rb', line 101

def builtin?
  type && type.builtin?
end

#nameObject



63
64
65
# File 'lib/wood/types.rb', line 63

def name
  [:array, type.name]
end

#node_nameObject



67
68
69
# File 'lib/wood/types.rb', line 67

def node_name
  :array_type
end

#numeric?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/wood/types.rb', line 97

def numeric?
  type && type.numeric?
end

#sexpObject



105
106
107
# File 'lib/wood/types.rb', line 105

def sexp
  [:array, type.sexp, size.sexp]
end