Module: Typed::Scala

Defined in:
lib/typed/scala.rb

Defined Under Namespace

Modules: Val, Var, Variables

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

module



116
117
118
119
120
121
# File 'lib/typed/scala.rb', line 116

def self.included(klass)
  super

  klass.extend Scala::Val
  klass.extend Scala::Var
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/typed/scala.rb', line 11

def [](key)
  if attrs.schema.exist?(key)
    attrs[key.to_s]
  else
    raise Typed::NotDefined, "#{key} is not a member of #{self.class}"
  end
end

#[]=(key, val) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/typed/scala.rb', line 19

def []=(key, val)
  if attrs.schema.exist?(key)
    if self.class.vals[key.to_s] and attrs.exist?(key)
      raise Typed::FixedValue, "reassignment to #{key}"
    end
    attrs[key.to_s] = val
  else
    raise Typed::NotDefined, "#{key} is not a member of #{self.class}"
  end
end

#attrsObject

instance methods



7
8
9
# File 'lib/typed/scala.rb', line 7

def attrs
  @attrs ||= Typed::Scala::Variables.build_attrs(self.class)
end