Sha256: 4a48829e501667964afc4053d143fd154496b76823f3412eeda1c836e5346229

Contents?: true

Size: 743 Bytes

Versions: 3

Compression:

Stored size: 743 Bytes

Contents

assert('Object#instance_exec') do
  class KlassWithSecret
    def initialize
      @secret = 99
    end
  end
  k = KlassWithSecret.new
  assert_equal 104, k.instance_exec(5) {|x| @secret+x }
end

assert('Object#tap') do
  ret = []
  (1..10)                 .tap {|x| ret << "original: #{x.inspect}"}
     .to_a                .tap {|x| ret << "array: #{x.inspect}"}
     .select {|x| x%2==0} .tap {|x| ret << "evens: #{x.inspect}"}
     .map { |x| x*x }     .tap {|x| ret << "squares: #{x.inspect}"}

  assert_equal [
    "original: 1..10",
    "array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
    "evens: [2, 4, 6, 8, 10]",
    "squares: [4, 16, 36, 64, 100]"
  ], ret
  assert_equal(:tap_ok, Class.new {def m; tap{return :tap_ok}; end}.new.m)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webruby-0.9.3 modules/mruby/mrbgems/mruby-object-ext/test/object.rb
webruby-0.9.2 modules/mruby/mrbgems/mruby-object-ext/test/object.rb
webruby-0.9.1 modules/mruby/mrbgems/mruby-object-ext/test/object.rb