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 " module RubyNext::Utils::A; end\n class RubyNext::Utils::B\n include RubyNext::Utils::A\n end\n\n using(Module.new do\n refine RubyNext::Utils::A do\n include(Module.new do\n def i_am_refinement\n \"yes, you are!\"\n end\n end)\n end\n end)\n\n RubyNext::Utils::B.new.i_am_refinement\n RUBY\n true\n rescue TypeError, NoMethodError\n false\n ensure\n $VERBOSE = save_verbose\n end\nend\n", TOPLEVEL_BINDING, __FILE__, __LINE__ + 1 |
.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 |