Class: Code::Object::Super

Inherits:
Function show all
Defined in:
lib/code/object/super.rb

Constant Summary collapse

CLASS_DOCUMENTATION =
{
  name: "Super",
  description:
    "calls the captured parent function available inside an extended function.",
  examples: [
    "Base = () => { self.name = :base self } Child = Base.extend(() => { super() }) Child().name",
    "Base = (name) => { self.name = name self } Child = Base.extend((...) => { super(...) }) Child(:ada).name",
    "Base = () => { 1 } Child = Base.extend(() => { super() + 1 }) Child()"
  ]
}.freeze

Constants inherited from Function

Function::INSTANCE_FUNCTIONS

Instance Attribute Summary

Attributes inherited from Function

#code_body, #code_parameters, #definition_context, #definition_object, #documentation, #instance_functions, #parent

Instance Method Summary collapse

Methods inherited from Function

#code_call, #code_class_functions, #code_deep_duplicate, #code_extend, #code_fetch, #code_functions, #code_get, #code_has_key?, #code_instance_functions, #code_replace, #code_set, #code_to_string, function_documentation, #signature_for_call

Constructor Details

#initialize(parent, forwarded_arguments, code_self, definition_context, explicit_arguments: false) ⇒ Super

Returns a new instance of Super.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/code/object/super.rb', line 16

def initialize(
  parent,
  forwarded_arguments,
  code_self,
  definition_context,
  explicit_arguments: false
)
  _explicit_arguments = explicit_arguments
  @parent = parent.to_code
  @forwarded_arguments = forwarded_arguments.to_code
  @code_self = code_self.to_code
  @definition_context = definition_context
  self.functions = Dictionary.new
  self.raw = @parent.raw
end

Instance Method Details

#call(**args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/code/object/super.rb', line 32

def call(**args)
  code_arguments = args.fetch(:arguments, List.new).to_code
  explicit_arguments = args.fetch(:explicit_arguments, false)

  @parent.code_call(
    *arguments_for(code_arguments, explicit_arguments).raw,
    explicit_arguments: explicit_arguments,
    bound_self: @code_self,
    **multi_fetch(args, *GLOBALS).merge(context: parent_context)
  )
end