module Vernacular
Allows extending ruby's syntax and compilation process
Constants
- VERSION
Attributes
iseq_dir[R]
modifiers[R]
Public Class Methods
add(modifier)
click to toggle source
# File lib/vernacular.rb, line 42 def add(modifier) modifiers << modifier end
clear()
click to toggle source
# File lib/vernacular.rb, line 46 def clear Dir.glob(File.join(iseq_dir, '**/*.yarb')) { |path| File.delete(path) } end
configure() { |self| ... }
click to toggle source
# File lib/vernacular.rb, line 50 def configure @modifiers = [] yield self hash = ConfigurationHash.new(modifiers).hash @iseq_dir = File.expand_path(File.join('../.iseq', hash), __dir__) FileUtils.mkdir_p(iseq_dir) unless File.directory?(iseq_dir) install end
give_me_all_the_things!()
click to toggle source
Use every available pre-configured modifier
# File lib/vernacular.rb, line 62 def give_me_all_the_things! @modifiers = Modifiers.constants.map { |constant| Modifiers.const_get(constant).new } end
iseq_path_for(source_path)
click to toggle source
# File lib/vernacular.rb, line 74 def iseq_path_for(source_path) source_path.gsub(/[^A-Za-z0-9\._-]/) { |c| format('%02x', c.ord) } .gsub('.rb', '.yarb') end
modify(source)
click to toggle source
# File lib/vernacular.rb, line 67 def modify(source) modifiers.each do |modifier| source = modifier.modify(source) end source end
Private Class Methods
install()
click to toggle source
# File lib/vernacular.rb, line 81 def install @installed ||= if defined?(Bootsnap) && using_bootsnap_compilation? class << Bootsnap::CompileCache::ISeq prepend ::Vernacular::BootsnapMixin end else class << RubyVM::InstructionSequence prepend ::Vernacular::InstructionSequenceMixin end end end
using_bootsnap_compilation?()
click to toggle source
# File lib/vernacular.rb, line 94 def using_bootsnap_compilation? filepath, = RubyVM::InstructionSequence.method(:load_iseq).source_location filepath =~ %r{/bootsnap/} rescue NameError false end