Sha256: dc7af091c7da0d2f5b1d67a9b36570e3e84cdb0271dfac3d9fb49ff4dc7fe186

Contents?: true

Size: 675 Bytes

Versions: 12

Compression:

Stored size: 675 Bytes

Contents

module Finitio
  class ProcWithCode < Proc

    def self.new(*args, &bl)
      return Proc.new(*args, &bl) unless args.size == 2 && bl.nil?

      p = Kernel.eval("->(#{args.first}){ #{args.last} }")
      p.instance_variable_set(:@_finitio_src, args)

      def p.finitio_src
        @_finitio_src
      end

      def p.hash
        @_finitio_src.hash
      end

      def p.==(other)
        super || (
          other.is_a?(Proc) &&
          other.respond_to?(:finitio_src) &&
          other.finitio_src == self.finitio_src
        )
      end

      def p.eql?(other)
        self.==(other)
      end

      p
    end

  end # module ProcWithCode
end # module Finitio

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
finitio-0.12.0 lib/finitio/support/proc_with_code.rb
finitio-0.11.4 lib/finitio/support/proc_with_code.rb
finitio-0.11.3 lib/finitio/support/proc_with_code.rb
finitio-0.11.2 lib/finitio/support/proc_with_code.rb
finitio-0.11.1 lib/finitio/support/proc_with_code.rb
finitio-0.10.0 lib/finitio/support/proc_with_code.rb
finitio-0.9.1 lib/finitio/support/proc_with_code.rb
finitio-0.9.0 lib/finitio/support/proc_with_code.rb
finitio-0.8.0 lib/finitio/support/proc_with_code.rb
finitio-0.7.0 lib/finitio/support/proc_with_code.rb
finitio-0.7.0.pre.rc4 lib/finitio/support/proc_with_code.rb
finitio-0.7.0.pre.rc3 lib/finitio/support/proc_with_code.rb