Sha256: ec1cd01613a799b367d1708b153c2c937893a8a1b4f4c1f38495f2b13ceb96c3

Contents?: true

Size: 417 Bytes

Versions: 15

Compression:

Stored size: 417 Bytes

Contents

require "myrrha/to_ruby_literal"

class Foo
  attr_reader :arg
  def initialize(arg)
    @arg = arg
  end
end

MyRules = Myrrha::ToRubyLiteral.dup.append do |r|
  r.coercion(Foo) do |foo, _|
    "Foo.new(#{foo.arg.inspect})"
  end
end

# Myrrha.to_ruby_literal is actually a shortcut for:
Myrrha::ToRubyLiteral.apply(Foo.new(:hello))
# => "Marshal.load('...')"

MyRules.apply(Foo.new(:hello))
# => "Foo.new(:hello)" 

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
myrrha-3.1.0 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0.rc7 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0.rc6 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0.rc5 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0.rc4 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0.rc3 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0.rc2 examples/to_ruby_literal_foo3.rb
myrrha-3.0.0.rc1 examples/to_ruby_literal_foo3.rb
myrrha-2.0.0 examples/to_ruby_literal_foo3.rb
myrrha-1.2.2 examples/to_ruby_literal_foo3.rb
myrrha-1.2.1 examples/to_ruby_literal_foo3.rb
myrrha-1.2.0 examples/to_ruby_literal_foo3.rb
myrrha-1.1.0 examples/to_ruby_literal_foo3.rb
myrrha-1.0.0 examples/to_ruby_literal_foo3.rb