Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python でもこんな感じのものを定義して
- # ["<a>" + e + "</a>" for e in r(['root1', ['branch0', 'branch1'], 'root2', ['branches'] ])]
- # って書きたい
- class Array
- def r &blk
- [].tap { |res|
- each { |e|
- if e.is_a? Array
- res << e.r(&blk)
- else
- res << blk.call(e)
- end
- }
- }
- end
- end
- if __FILE__ == $PROGRAM_NAME
- require "test/unit"
- class TestR < Test::Unit::TestCase
- def test_r
- assert_equal ['root1', ['branch0', 'branch1'], 'root2', ['branches'] ].r { |e|
- '<a>' + e + '</a>'
- }, ["<a>root1</a>", ["<a>branch0</a>", "<a>branch1</a>"], "<a>root2</a>", ["<a>branches</a>"]]
- end
- end
- end
Add Comment
Please, Sign In to add comment