Skip to content

Instantly share code, notes, and snippets.

@oki
Created January 22, 2009 20:41
Show Gist options
  • Save oki/50703 to your computer and use it in GitHub Desktop.
Save oki/50703 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"]
# ..
>> a = [2,3]
=> [2, 3]
>> a.what?(42) == [42,2,3]
Nothing known about 42
[2, 3].unshift(42) == [42, 2, 3]
=> ["unshift"]
# 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