Skip to content

Instantly share code, notes, and snippets.

@ravicious
Forked from oki/gist:50703
Created January 22, 2009 20:53
Show Gist options
  • Save ravicious/50712 to your computer and use it in GitHub Desktop.
Save ravicious/50712 to your computer and use it in GitHub Desktop.
# mam dwie tablice:
# a = [1,2]
# b = [3,4],
# chce je polaczyc w nastepujacy sposob: [[1,3],[2,4]]
# pytam wiec irba jak to zrobic :-)
>> a = [1,2]
=> [1, 2]
>> b = [3,4]
=> [3, 4]
>> a.what?(b) == [[1,3],[2,4]]
[1, 2].zip([3, 4]) == [[1, 3], [2, 4]]
=> ["zip"]
=> 1.240 seconds :)
>> a
=> [1, 2]
>> a.zip(b)
=> [[1, 3], [2, 4]]
# inny przyklad:
>> c = (1..3).to_a
=> [1, 2, 3]
>> c.what? == [3,2,1]
[1, 2, 3].reverse! == [3, 2, 1]
[1, 2, 3].reverse == [3, 2, 1]
=> ["reverse!", "reverse"]
# kolejny:
>> " abc ".what? == "abc"
" abc ".strip! == "abc"
" abc ".strip == "abc"
=> ["strip!", "strip"]
# to jest piekne ;-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment