From f3a5653837442e7740c66345231f31764df9950e Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 22 Jun 2015 16:30:44 -0600 Subject: [PATCH] fix compatibility with Ruby 2.0 --- .../formatted_text/inline_image_arranger.rb | 4 +++- .../prawn_ext/formatted_text/fragment.rb | 17 +++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/asciidoctor-pdf/formatted_text/inline_image_arranger.rb b/lib/asciidoctor-pdf/formatted_text/inline_image_arranger.rb index 61de43170..0a56b8960 100644 --- a/lib/asciidoctor-pdf/formatted_text/inline_image_arranger.rb +++ b/lib/asciidoctor-pdf/formatted_text/inline_image_arranger.rb @@ -116,7 +116,9 @@ def arrange_images fragments end if ::RUBY_MIN_VERSION_2 - ::Prawn::Text::Formatted::Box.prepend InlineImageArranger + class ::Prawn::Text::Formatted::Box + prepend InlineImageArranger + end else ::Prawn::Text::Formatted::Box.extensions << InlineImageArranger end diff --git a/lib/asciidoctor-pdf/prawn_ext/formatted_text/fragment.rb b/lib/asciidoctor-pdf/prawn_ext/formatted_text/fragment.rb index abbdb3a58..ba3a7fc8a 100644 --- a/lib/asciidoctor-pdf/prawn_ext/formatted_text/fragment.rb +++ b/lib/asciidoctor-pdf/prawn_ext/formatted_text/fragment.rb @@ -22,14 +22,15 @@ def descender= val end end -if ::RUBY_MIN_VERSION_2 - ::Prawn::Text::Formatted::Fragment.prepend Fragment -else - # NOTE it's necessary to first remove the accessor methods we are replacing - ::Prawn::Text::Formatted::Fragment.__send__ :remove_method, :ascender= - ::Prawn::Text::Formatted::Fragment.__send__ :remove_method, :descender= - # NOTE we use __send__ since :include wasn't public until Ruby 2.0 - ::Prawn::Text::Formatted::Fragment.__send__ :include, Fragment +class ::Prawn::Text::Formatted::Fragment + if ::RUBY_MIN_VERSION_2 + prepend Fragment + else + # NOTE it's necessary to remove the accessor methods or else they won't get replaced + remove_method :ascender= + remove_method :descender= + include Fragment + end end end end