File: test_kernel_1_9_features.rb

package info (click to toggle)
jruby 1.5.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 46,252 kB
  • ctags: 72,039
  • sloc: ruby: 398,155; java: 169,482; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (21 lines) | stat: -rw-r--r-- 632 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'test/unit'

class A
  define_singleton_method(:a) { 42 }
  define_singleton_method(:b, lambda {|x| 2*x })
end

class TestKernel19Features < Test::Unit::TestCase
  def test_proc_lambda
    # proc does not check arity in 1.9
    assert_nothing_raised { proc {|a,b|}.call(1) }
  end

  def test_define_singleton_method
    assert(::A.singleton_methods.include?(:a), "singleton method :a defined")
    assert_equal( 42, A.a, "singleton method :a returns 42" )

    assert(::A.singleton_methods.include?(:b), "singleton method :b defined")
    assert_equal( 84, A.b(42), "singleton method :b returns double the input")
  end
end