Module: RubyNext::Utils
- Defined in:
- lib/ruby-next/utils.rb
Class Method Summary collapse
-
.refine_modules? ⇒ Boolean
Returns true if modules refinement is supported in current version.
- .source_with_lines(source, path) ⇒ Object
Class Method Details
.refine_modules? ⇒ Boolean
Returns true if modules refinement is supported in current version
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby-next/utils.rb', line 16 def refine_modules? save_verbose, $VERBOSE = $VERBOSE, nil @refine_modules ||= begin # Make sure that including modules within refinements works # See https://github.com/oracle/truffleruby/issues/2026 eval <<~RUBY, TOPLEVEL_BINDING, __FILE__, __LINE__ + 1 module RubyNext::Utils::A; end class RubyNext::Utils::B include RubyNext::Utils::A end using(Module.new do refine RubyNext::Utils::A do include(Module.new do def i_am_refinement "yes, you are!" end end) end end) RubyNext::Utils::B.new.i_am_refinement RUBY true rescue TypeError, NoMethodError false ensure $VERBOSE = save_verbose end end |
.source_with_lines(source, path) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ruby-next/utils.rb', line 7 def source_with_lines(source, path) source.lines.map.with_index do |line, i| "#{(i + 1).to_s.rjust(4)}: #{line}" end.tap do |lines| lines.unshift " 0: # source: #{path}" end end |