Skip to content

Commit 7d5a220

Browse files
committed
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.
1 parent 2e30594 commit 7d5a220

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

lib/pp.rb

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -530,37 +530,39 @@ def pretty_print(q) # :nodoc:
530530
end
531531
end
532532

533-
class RubyVM::AbstractSyntaxTree::Node
534-
def pretty_print_children(q, names = [])
535-
children.zip(names) do |c, n|
536-
if n
537-
q.breakable
538-
q.text "#{n}:"
539-
end
540-
q.group(2) do
541-
q.breakable
542-
q.pp c
533+
if defined?(RubyVM::AbstractSyntaxTree)
534+
class RubyVM::AbstractSyntaxTree::Node
535+
def pretty_print_children(q, names = [])
536+
children.zip(names) do |c, n|
537+
if n
538+
q.breakable
539+
q.text "#{n}:"
540+
end
541+
q.group(2) do
542+
q.breakable
543+
q.pp c
544+
end
543545
end
544546
end
545-
end
546547

547-
def pretty_print(q)
548-
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
549-
case type
550-
when :SCOPE
551-
pretty_print_children(q, %w"tbl args body")
552-
when :ARGS
553-
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
554-
when :DEFN
555-
pretty_print_children(q, %w[mid body])
556-
when :ARYPTN
557-
pretty_print_children(q, %w[const pre rest post])
558-
when :HSHPTN
559-
pretty_print_children(q, %w[const kw kwrest])
560-
else
561-
pretty_print_children(q)
562-
end
563-
}
548+
def pretty_print(q)
549+
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
550+
case type
551+
when :SCOPE
552+
pretty_print_children(q, %w"tbl args body")
553+
when :ARGS
554+
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
555+
when :DEFN
556+
pretty_print_children(q, %w[mid body])
557+
when :ARYPTN
558+
pretty_print_children(q, %w[const pre rest post])
559+
when :HSHPTN
560+
pretty_print_children(q, %w[const kw kwrest])
561+
else
562+
pretty_print_children(q)
563+
end
564+
}
565+
end
564566
end
565567
end
566568

0 commit comments

Comments
 (0)