Class: Halunke::Runtime::HClass
- Inherits:
-
Object
- Object
- Halunke::Runtime::HClass
- Defined in:
- lib/halunke/runtime/hclass.rb
Instance Attribute Summary collapse
-
#instance_methods ⇒ Object
readonly
Returns the value of attribute instance_methods.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_attribute?(attribute_name) ⇒ Boolean
- #create_instance(value = nil, source_code_position: NullSourceCodePosition.new) ⇒ Object
-
#initialize(name, allowed_attributes, instance_methods, class_methods, native) ⇒ HClass
constructor
A new instance of HClass.
- #inspect(_context) ⇒ Object
- #lookup(message) ⇒ Object
- #native? ⇒ Boolean
- #receive_message(context, message_name, message_value, source_code_position: NullSourceCodePosition.new) ⇒ Object
- #runtime_class ⇒ Object
Constructor Details
#initialize(name, allowed_attributes, instance_methods, class_methods, native) ⇒ HClass
Returns a new instance of HClass.
10 11 12 13 14 15 16 |
# File 'lib/halunke/runtime/hclass.rb', line 10 def initialize(name, allowed_attributes, instance_methods, class_methods, native) @name = name @allowed_attributes = allowed_attributes @instance_methods = instance_methods @class_methods = class_methods @native = native end |
Instance Attribute Details
#instance_methods ⇒ Object (readonly)
Returns the value of attribute instance_methods.
8 9 10 |
# File 'lib/halunke/runtime/hclass.rb', line 8 def instance_methods @instance_methods end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/halunke/runtime/hclass.rb', line 7 def name @name end |
Class Method Details
.receive_message(context, message_name, message_value, source_code_position: NullSourceCodePosition.new) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/halunke/runtime/hclass.rb', line 19 def (context, , , source_code_position: NullSourceCodePosition.new) case when "new attributes methods class_methods" name = determine_name([0]) allowed_attributes = determine_allowed_attributes([1]) instance_methods = determine_methods([2]) class_methods = determine_methods([3]) when "new attributes methods" name = determine_name([0]) allowed_attributes = determine_allowed_attributes([1]) instance_methods = determine_methods([2]) class_methods = {} when "new methods" name = determine_name([0]) allowed_attributes = [] instance_methods = determine_methods([1]) class_methods = {} else = ["new attributes methods class_methods", "new attributes methods", "new methods"] raise HUnknownMessage.new("Class", , , source_code_position) end context[name] = HClass.new(name, allowed_attributes, instance_methods, class_methods, false) rescue FrozenError assigned_value = context[name].inspect(context) raise HBarewordAlreadyAssigned.new("Bareword '#{name} is already assigned to #{assigned_value}. In Halunke, you can only assign once.", [0].source_code_position) end |
Instance Method Details
#allowed_attribute?(attribute_name) ⇒ Boolean
94 95 96 |
# File 'lib/halunke/runtime/hclass.rb', line 94 def allowed_attribute?(attribute_name) @allowed_attributes.include? attribute_name end |
#create_instance(value = nil, source_code_position: NullSourceCodePosition.new) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/halunke/runtime/hclass.rb', line 98 def create_instance(value = nil, source_code_position: NullSourceCodePosition.new) if native? HNativeObject.new(self, value, source_code_position: source_code_position) else HObject.new(self, value ? value.ruby_value : {}, source_code_position: source_code_position) end end |
#inspect(_context) ⇒ Object
110 111 112 |
# File 'lib/halunke/runtime/hclass.rb', line 110 def inspect(_context) "Class #{@name}" end |
#lookup(message) ⇒ Object
106 107 108 |
# File 'lib/halunke/runtime/hclass.rb', line 106 def lookup() @instance_methods.fetch() end |
#native? ⇒ Boolean
118 119 120 |
# File 'lib/halunke/runtime/hclass.rb', line 118 def native? @native end |
#receive_message(context, message_name, message_value, source_code_position: NullSourceCodePosition.new) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/halunke/runtime/hclass.rb', line 82 def (context, , , source_code_position: NullSourceCodePosition.new) if == "new" && !native? create_instance([0], source_code_position: source_code_position) elsif @class_methods.key? m = @class_methods[] m.(context, "call", [HArray.create_instance([self].concat())], source_code_position: source_code_position) else raise HUnknownMessage.new(self.inspect(context), , @class_methods.keys, source_code_position) end end |
#runtime_class ⇒ Object
114 115 116 |
# File 'lib/halunke/runtime/hclass.rb', line 114 def runtime_class self end |