Class: Riml::ClassDefinitionNode

Inherits:
Struct
  • Object
show all
Includes:
Visitable, Walkable
Defined in:
lib/nodes.rb

Constant Summary collapse

FUNCTIONS =
lambda {|expr| DefNode === expr}
DEFAULT_SCOPE_MODIFIER =
's:'

Constants included from Visitable

Visitable::DESCENDANT_OF_REGEX

Instance Attribute Summary collapse

Attributes included from Visitable

#compiled_output, #force_newline, #parent_node, #scope

Instance Method Summary collapse

Methods included from Walkable

#child_after, #child_previous_to, #each, #index_by_children, #index_by_member, #insert_after, #insert_before, #next, #previous, #remove, #replace_with

Methods included from Visitable

#accept, #method_missing, #respond_to?

Constructor Details

#initializeClassDefinitionNode

Returns a new instance of ClassDefinitionNode.



944
945
946
947
948
949
950
951
# File 'lib/nodes.rb', line 944

def initialize(*)
  super
  unless scope_modifier
    self.scope_modifier = DEFAULT_SCOPE_MODIFIER
  end
  # registered with ClassMap
  @registered_state = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Riml::Visitable

Instance Attribute Details

#expressionsObject

Returns the value of attribute expressions

Returns:

  • (Object)

    the current value of expressions



937
938
939
# File 'lib/nodes.rb', line 937

def expressions
  @expressions
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



937
938
939
# File 'lib/nodes.rb', line 937

def name
  @name
end

#scope_modifierObject

Returns the value of attribute scope_modifier

Returns:

  • (Object)

    the current value of scope_modifier



937
938
939
# File 'lib/nodes.rb', line 937

def scope_modifier
  @scope_modifier
end

#superclass_nameObject Also known as: superclass_full_name

Returns the value of attribute superclass_name

Returns:

  • (Object)

    the current value of superclass_name



937
938
939
# File 'lib/nodes.rb', line 937

def superclass_name
  @superclass_name
end

Instance Method Details

#childrenObject



1000
1001
1002
# File 'lib/nodes.rb', line 1000

def children
  [expressions]
end

#constructorObject Also known as: constructor?



963
964
965
966
967
968
969
970
971
972
973
974
# File 'lib/nodes.rb', line 963

def constructor
  expressions.nodes.detect do |n|
    next(false) unless DefNode === n && (n.name == 'initialize' || n.name == constructor_name)
    if n.instance_of?(DefMethodNode)
      Riml.warn("class #{full_name.inspect} has an initialize function declared with 'defm'. Please use 'def'.")
      new_node = n.to_def_node
      new_node.keywords = nil
      n.replace_with(new_node)
    end
    true
  end
end

#constructor_full_nameObject



988
989
990
# File 'lib/nodes.rb', line 988

def constructor_full_name
  "#{scope_modifier}#{name}Constructor"
end

#constructor_nameObject



984
985
986
# File 'lib/nodes.rb', line 984

def constructor_name
  "#{name}Constructor"
end

#constructor_obj_nameObject



992
993
994
# File 'lib/nodes.rb', line 992

def constructor_obj_name
  name[0].downcase + name[1..-1] + "Obj"
end

#find_function(scope_modifier, name) ⇒ Object Also known as: has_function?



977
978
979
980
981
# File 'lib/nodes.rb', line 977

def find_function(scope_modifier, name)
  expressions.nodes.select(&FUNCTIONS).detect do |def_node|
    def_node.name == name && def_node.scope_modifier == scope_modifier
  end
end

#full_nameObject



957
958
959
# File 'lib/nodes.rb', line 957

def full_name
  scope_modifier + name
end

#private_function_namesObject



996
997
998
# File 'lib/nodes.rb', line 996

def private_function_names
  @private_function_names ||= []
end

#superclass?Boolean

Returns:

  • (Boolean)


953
954
955
# File 'lib/nodes.rb', line 953

def superclass?
  not superclass_name.nil?
end