Module: Noraneko::NodeUtility
- Included in:
- Processor
- Defined in:
- lib/noraneko/node_utility.rb
Instance Method Summary collapse
- #convert_to_hash(node) ⇒ Object
- #extract_consts(const_node, consts = []) ⇒ Object
- #extract_syms(nodes) ⇒ Object
- #singleton_class?(node) ⇒ Boolean
Instance Method Details
#convert_to_hash(node) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/noraneko/node_utility.rb', line 19 def convert_to_hash(node) raise 'This is not hash expression' unless node.type == :hash node.children.each_with_object({}) do |pair, hash| key, value = pair.children if convertable?(key) && convertable?(value) hash[convert!(key)] = convert!(value) end end end |
#extract_consts(const_node, consts = []) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/noraneko/node_utility.rb', line 5 def extract_consts(const_node, consts = []) next_const_node, const_sym = const_node.children consts.unshift(const_sym) if next_const_node extract_consts(next_const_node, consts) else consts end end |
#extract_syms(nodes) ⇒ Object
15 16 17 |
# File 'lib/noraneko/node_utility.rb', line 15 def extract_syms(nodes) nodes.map { |n| n.children.last } end |
#singleton_class?(node) ⇒ Boolean
29 30 31 |
# File 'lib/noraneko/node_utility.rb', line 29 def singleton_class?(node) node&.children&.first&.type == :self end |