Sha256: 2362bb08fbccdcdf3c366efe7cff9d5d7429ef02d35ebc46d148a88c5df75ffa

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

require 'blankslate'

module DslAccessor
  module AutoDeclare
    class DefineClassMethod < BasicObject
      def initialize(context, &block)
        @context = context
        instance_eval(&block)
      end

      private
        def method_missing(name, *args, &block)
          if args.empty? and block
            meta_class = (class << @context; self; end)
            meta_class.class_eval{ define_method(name, &block) }
          else
            @context.__send__(name, *args, &block)
          end
        end
    end

    class DefineInstanceMethod < BasicObject
      def initialize(klass, &block)
        @klass = klass
        instance_eval(&block)
      end

      private
        def method_missing(name, *args, &block)
          if args.empty? and block
            @klass.class_eval{ define_method(name, &block) }
          else
            raise NameError, "undefined local variable or method `#{name}'"
          end
        end
    end
  end
end


__END__

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
genki-dsl_accessor-0.4.2 lib/dsl_accessor/auto_declare.rb