Sha256: bd027e2fc0d3c1289986b1d0fd938a8308db674da99a3607d40eac83d0528c06

Contents?: true

Size: 627 Bytes

Versions: 2

Compression:

Stored size: 627 Bytes

Contents

module Naught
  class NullClassBuilder
    module Commands
      class DefineExplicitConversions
        def initialize(builder)
          @builder = builder
        end

        def call
          defer do |subject|
            subject.module_eval do
              def to_s; ""; end
              def to_i; 0; end
              def to_f; 0.0; end
              def to_c; 0.to_c; end
              def to_r; 0.to_r; end
              def to_a; []; end
              def to_h; {}; end
            end
          end
        end

        def defer(&block)
          @builder.defer(&block)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
naught-0.0.2 lib/naught/null_class_builder/commands/define_explicit_conversions.rb
naught-0.0.1 lib/naught/null_class_builder/commands/define_explicit_conversions.rb