Module: Cube::CubeMethods

Defined in:
lib/cube/toplevel.rb

Instance Method Summary collapse

Instance Method Details

#as_interface(iface, runtime_checks: true) ⇒ Object

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cube/toplevel.rb', line 77

def as_interface(iface, runtime_checks: true)
  raise ArgumentError, "#{iface} is not a Cube::Interface" unless iface.is_a?(Cube::Interface)
  implements = lambda { |this|
    unless this.is_a? Class
      raise "Non-Class modules cannot implement interfaces"
    end
    this.instance_variable_set(:@__interface_runtime_check, true) if runtime_checks
    this.include(iface)
  }
  implements.call(clone)
end

#shell_implements(mod) ⇒ Object



90
91
92
93
94
# File 'lib/cube/toplevel.rb', line 90

def shell_implements(mod)
  instance_variable_set(:@__interface_runtime_check, false)
  instance_variable_set(:@__interface_arity_skip, true)
  include(mod)
end