Sha256: d4a00d874bc5e5c74e17426244dd13516c4beed587f071f5cf503d961d31a6d0

Contents?: true

Size: 938 Bytes

Versions: 5

Compression:

Stored size: 938 Bytes

Contents

require 'test/unit'
require 'rbconfig'

dir = File.dirname(__FILE__)
$:.unshift(dir) if not $:.include?(dir)
$:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
$:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")

require 'internal/module'
require 'internal/method'
require 'internal/noex'

$stdout.sync = true
$stderr.sync = true

class TC_Module < Test::Unit::TestCase
  module Foo
    def foo(n=1)
      # A fancy way to return 42
      if false then
        answer = 0
      else
        answer = 0
        (1..42).each do |i|
          answer += (i / i)
        end
      end
      return n * answer
    end
  end

  include Foo

  def test_add_method
    m = method(:foo)
    n = m.body
    klass = Class.new
    klass.instance_eval do
      add_method(:foo, n, Noex::PUBLIC)
    end
    obj = klass.new
    assert_equal 42, obj.foo
  end
end

if __FILE__ == $0 then
  # exit Test::Unit::AutoRunner.run
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby-internal-0.8.3 test/test_module.rb
ruby-internal-0.8.2 test/test_module.rb
ruby-internal-0.8.1 test/test_module.rb
ruby-internal-0.8.0 test/test_module.rb
ruby-internal-0.7.3 test/test_module.rb