Class: Riml::ClassDefinitionNode

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

Constant Summary collapse

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

Constants included from Visitable

Visitable::EMPTY_CHILDREN

Instance Attribute Summary collapse

Attributes included from Visitable

#compiled_output, #force_newline, #parent_node, #parser_info, #scope

Instance Method Summary collapse

Methods included from Visitable

#accept, #force_newline_if_child_call_node?, #location_info

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

Constructor Details

#initializeClassDefinitionNode

Returns a new instance of ClassDefinitionNode.



961
962
963
964
965
966
967
968
# File 'lib/riml/nodes.rb', line 961

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

Instance Attribute Details

#expressionsObject

Returns the value of attribute expressions

Returns:

  • (Object)

    the current value of expressions



955
956
957
# File 'lib/riml/nodes.rb', line 955

def expressions
  @expressions
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



955
956
957
# File 'lib/riml/nodes.rb', line 955

def name
  @name
end

#scope_modifierObject

Returns the value of attribute scope_modifier

Returns:

  • (Object)

    the current value of scope_modifier



955
956
957
# File 'lib/riml/nodes.rb', line 955

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



955
956
957
# File 'lib/riml/nodes.rb', line 955

def superclass_name
  @superclass_name
end

Instance Method Details

#childrenObject



1023
1024
1025
# File 'lib/riml/nodes.rb', line 1023

def children
  [expressions]
end

#constructorObject Also known as: constructor?



986
987
988
989
990
991
992
993
994
995
996
997
# File 'lib/riml/nodes.rb', line 986

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



1011
1012
1013
# File 'lib/riml/nodes.rb', line 1011

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

#constructor_nameObject



1007
1008
1009
# File 'lib/riml/nodes.rb', line 1007

def constructor_name
  "#{name}Constructor"
end

#constructor_obj_nameObject



1015
1016
1017
# File 'lib/riml/nodes.rb', line 1015

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

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



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

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



980
981
982
# File 'lib/riml/nodes.rb', line 980

def full_name
  scope_modifier + name
end

#imported?Boolean

This if for the AST_Rewriter, checking if a class is an ‘ImportedClass` or not without resorting to type checking.

Returns:

  • (Boolean)


976
977
978
# File 'lib/riml/nodes.rb', line 976

def imported?
  false
end

#private_function_namesObject



1019
1020
1021
# File 'lib/riml/nodes.rb', line 1019

def private_function_names
  @private_function_names ||= []
end

#superclass?Boolean

Returns:

  • (Boolean)


970
971
972
# File 'lib/riml/nodes.rb', line 970

def superclass?
  not superclass_name.nil?
end