Class: DRG::Ruby::Const
- Inherits:
-
Object
- Object
- DRG::Ruby::Const
- Defined in:
- lib/drg/ruby/const.rb
Direct Known Subclasses
Constant Summary collapse
- CONSTANT_DEFS =
{ :class => :class, :module => :module, :cdecl => :class }
Instance Attribute Summary collapse
-
#sexp ⇒ Object
readonly
Returns the value of attribute sexp.
Instance Method Summary collapse
- #class? ⇒ Boolean
- #class_vars ⇒ Object
- #func_by_name(name_as_symbol) ⇒ Object
- #funcs ⇒ Object
- #initialization_args ⇒ Object
-
#initialize(sexp) ⇒ Const
constructor
A new instance of Const.
- #instance_vars ⇒ Object
- #module? ⇒ Boolean
- #name(sexp = @sexp, list = []) ⇒ Object
- #type(sexp = @sexp, val = nil) ⇒ Object
Constructor Details
#initialize(sexp) ⇒ Const
Returns a new instance of Const.
9 10 11 12 |
# File 'lib/drg/ruby/const.rb', line 9 def initialize(sexp) sexp = sexp.select { |x| x.is_a?(Array) }.last if sexp[0] == :block @sexp = sexp end |
Instance Attribute Details
#sexp ⇒ Object (readonly)
Returns the value of attribute sexp.
6 7 8 |
# File 'lib/drg/ruby/const.rb', line 6 def sexp @sexp end |
Instance Method Details
#class? ⇒ Boolean
47 48 49 |
# File 'lib/drg/ruby/const.rb', line 47 def class? type == :class end |
#class_vars ⇒ Object
60 61 |
# File 'lib/drg/ruby/const.rb', line 60 def class_vars end |
#func_by_name(name_as_symbol) ⇒ Object
39 40 41 |
# File 'lib/drg/ruby/const.rb', line 39 def func_by_name(name_as_symbol) funcs.find { |x| x.name == name_as_symbol } end |
#funcs ⇒ Object
43 44 45 |
# File 'lib/drg/ruby/const.rb', line 43 def funcs @funcs ||= load_funkyness end |
#initialization_args ⇒ Object
35 36 37 |
# File 'lib/drg/ruby/const.rb', line 35 def initialization_args funcs.find(-> { OpenStruct.new }) { |func| func.name == :initialize }.args.to_a end |
#instance_vars ⇒ Object
56 57 |
# File 'lib/drg/ruby/const.rb', line 56 def instance_vars end |
#module? ⇒ Boolean
51 52 53 |
# File 'lib/drg/ruby/const.rb', line 51 def module? type == :module end |
#name(sexp = @sexp, list = []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/drg/ruby/const.rb', line 14 def name(sexp = @sexp, list = []) sexp = Array(sexp) if sexp[1].is_a?(Sexp) && sexp[1][0] == :colon2 parts = sexp[1].to_a.flatten list.concat parts.drop(parts.size / 2) elsif CONSTANT_DEFS.key?(sexp[0]) name(sexp.compact[2], list << sexp[1].to_s) end list.join('::') end |
#type(sexp = @sexp, val = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/drg/ruby/const.rb', line 25 def type(sexp = @sexp, val = nil) sexp = Array(sexp) if sexp[1].is_a?(Sexp) && sexp[1][0] == :colon2 val = sexp[0] elsif CONSTANT_DEFS.key?(sexp[0]) val = type(sexp.compact[2], sexp[0]) end CONSTANT_DEFS[val] end |