diff options
author | Charles Oliver Nutter <headius@headius.com> | 2021-09-23 23:57:26 -0500 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-12-18 08:38:58 +0900 |
commit | 5a6baaba3881c04534c9ad959e427ade3d5e410b (patch) | |
tree | 1ffb2b3e61dfbba2dd61991d3576ce42c0aa93d4 /lib | |
parent | de6ef2ca71453cd7a9a10943dc082718ea2f8f17 (diff) |
[ruby/pp] Only do RubyVM patches if class exists
This class does not exist in any implementation except CRuby.
I would recommend moving this code somewhere else, like a separate
file loaded only on CRuby or into CRuby itself. For now this
change is sufficient to load the library on other implementations.
https://github.com/ruby/pp/commit/7d5a220f64
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pp.rb | 58 |
1 files changed, 30 insertions, 28 deletions
@@ -539,37 +539,39 @@ class MatchData # :nodoc: end end -class RubyVM::AbstractSyntaxTree::Node - def pretty_print_children(q, names = []) - children.zip(names) do |c, n| - if n - q.breakable - q.text "#{n}:" - end - q.group(2) do - q.breakable - q.pp c +if defined?(RubyVM::AbstractSyntaxTree) + class RubyVM::AbstractSyntaxTree::Node + def pretty_print_children(q, names = []) + children.zip(names) do |c, n| + if n + q.breakable + q.text "#{n}:" + end + q.group(2) do + q.breakable + q.pp c + end end end - end - def pretty_print(q) - q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") { - case type - when :SCOPE - pretty_print_children(q, %w"tbl args body") - when :ARGS - pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block]) - when :DEFN - pretty_print_children(q, %w[mid body]) - when :ARYPTN - pretty_print_children(q, %w[const pre rest post]) - when :HSHPTN - pretty_print_children(q, %w[const kw kwrest]) - else - pretty_print_children(q) - end - } + def pretty_print(q) + q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") { + case type + when :SCOPE + pretty_print_children(q, %w"tbl args body") + when :ARGS + pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block]) + when :DEFN + pretty_print_children(q, %w[mid body]) + when :ARYPTN + pretty_print_children(q, %w[const pre rest post]) + when :HSHPTN + pretty_print_children(q, %w[const kw kwrest]) + else + pretty_print_children(q) + end + } + end end end |