Created
October 20, 2012 22:52
-
-
Save syntacticsugar/3925114 to your computer and use it in GitHub Desktop.
wherein i lose my shit and go to town playing with Rubified `car`/`cdr`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Death-Lair-of-Killer-Bambi:Desktop stickycake$ irb | |
cannot load such file -- irb/autocompletion | |
1.9.3-p194 :001 > boys = %w{jarry larry parry gary} | |
=> ["jarry", "larry", "parry", "gary"] | |
1.9.3-p194 :002 > boys.is_a(Array) | |
NoMethodError: undefined method `is_a' for ["jarry", "larry", "parry", "gary"]:Array | |
from (irb):2 | |
from /Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>' | |
1.9.3-p194 :003 > boys.is_a?(Array) | |
=> true | |
1.9.3-p194 :004 > !boys.is_a?(String) | |
=> true | |
1.9.3-p194 :005 > boys[0] | |
=> "jarry" | |
1.9.3-p194 :006 > boys.[1..-1] | |
SyntaxError: (irb):6: syntax error, unexpected '[' | |
boys.[1..-1] | |
^ | |
(irb):6: syntax error, unexpected ']', expecting $end | |
from /Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>' | |
1.9.3-p194 :007 > boys | |
=> ["jarry", "larry", "parry", "gary"] | |
1.9.3-p194 :008 > boys[1..-1] | |
=> ["larry", "parry", "gary"] | |
1.9.3-p194 :009 > girls = %w(sasha jenna krystal breanna jade nikki sara terry poppy) | |
=> ["sasha", "jenna", "krystal", "breanna", "jade", "nikki", "sara", "terry", "poppy"] | |
1.9.3-p194 :010 > girls | |
=> ["sasha", "jenna", "krystal", "breanna", "jade", "nikki", "sara", "terry", "poppy"] | |
1.9.3-p194 :011 > def array? | |
1.9.3-p194 :012?> self.is_a?(Array) | |
1.9.3-p194 :013?> end | |
=> nil | |
1.9.3-p194 :014 > girls.array? | |
=> true | |
1.9.3-p194 :015 > def first | |
1.9.3-p194 :016?> self[0] | |
1.9.3-p194 :017?> end | |
=> nil | |
1.9.3-p194 :018 > def rest | |
1.9.3-p194 :019?> self[1..-1] | |
1.9.3-p194 :020?> end | |
=> nil | |
1.9.3-p194 :021 > girls.first | |
=> "sasha" | |
1.9.3-p194 :022 > girls.rest | |
=> ["jenna", "krystal", "breanna", "jade", "nikki", "sara", "terry", "poppy"] | |
1.9.3-p194 :023 > girls[2..6] | |
=> ["krystal", "breanna", "jade", "nikki", "sara"] | |
1.9.3-p194 :024 > darks = %w(coal charcoal slate rust maroon ebony) | |
=> ["coal", "charcoal", "slate", "rust", "maroon", "ebony"] | |
1.9.3-p194 :025 > mediums = %w(med1 med2 med med4 med5) | |
=> ["med1", "med2", "med", "med4", "med5"] | |
1.9.3-p194 :026 > lights = %w(light1 light2 light3 light4) | |
=> ["light1", "light2", "light3", "light4"] | |
1.9.3-p194 :027 > jill << lights << mediums << darks | |
NameError: undefined local variable or method `jill' for main:Object | |
from (irb):27 | |
from /Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>' | |
1.9.3-p194 :028 > jill = Array.new << lights << mediums << darks | |
=> [["light1", "light2", "light3", "light4"], ["med1", "med2", "med", "med4", "med5"], ["coal", "charcoal", "slate", "rust", "maroon", "ebony"]] | |
1.9.3-p194 :029 > darks.first | |
=> "coal" | |
1.9.3-p194 :030 > colors.rest.first | |
NameError: undefined local variable or method `colors' for main:Object | |
from (irb):30 | |
from /Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>' | |
1.9.3-p194 :031 > jill.rest.first | |
=> ["med1", "med2", "med", "med4", "med5"] | |
1.9.3-p194 :032 > colors = jill.clone | |
=> [["light1", "light2", "light3", "light4"], ["med1", "med2", "med", "med4", "med5"], ["coal", "charcoal", "slate", "rust", "maroon", "ebony"]] | |
1.9.3-p194 :033 > colors | |
=> [["light1", "light2", "light3", "light4"], ["med1", "med2", "med", "med4", "med5"], ["coal", "charcoal", "slate", "rust", "maroon", "ebony"]] | |
1.9.3-p194 :034 > colors.rest.rest.first | |
=> ["coal", "charcoal", "slate", "rust", "maroon", "ebony"] | |
1.9.3-p194 :035 > colors.rest.rest.first.first | |
=> "coal" | |
1.9.3-p194 :036 > colors .rest.rest | |
=> [["coal", "charcoal", "slate", "rust", "maroon", "ebony"]] | |
1.9.3-p194 :037 > colors.rest.rest | |
=> [["coal", "charcoal", "slate", "rust", "maroon", "ebony"]] | |
1.9.3-p194 :038 > colors.rest.rest.rest | |
=> [] | |
1.9.3-p194 :039 > colors.rest.rest.first | |
=> ["coal", "charcoal", "slate", "rust", "maroon", "ebony"] | |
1.9.3-p194 :040 > colors.rest.rest | |
=> [["coal", "charcoal", "slate", "rust", "maroon", "ebony"]] | |
1.9.3-p194 :041 > colors.rest.rest.rest | |
=> [] | |
1.9.3-p194 :042 > colors.rest.rest.first | |
=> ["coal", "charcoal", "slate", "rust", "maroon", "ebony"] | |
1.9.3-p194 :043 > colors.rest.rest.first.rest.first | |
=> "charcoal" | |
1.9.3-p194 :044 > colors.rest.rest.first.rest.rest.rest | |
=> ["rust", "maroon", "ebony"] | |
1.9.3-p194 :045 > colors.rest.rest.first.rest.rest.rest.rest.rest | |
=> ["ebony"] | |
1.9.3-p194 :046 > colors.rest.rest.first.rest.rest.rest.rest.rest.rest | |
=> [] | |
1.9.3-p194 :047 > colors.rest.rest.first.rest.rest.rest.rest.rest.rest | |
=> [] | |
1.9.3-p194 :048 > colors.rest.rest.first.rest.rest.rest.rest.rest.rest.rest | |
=> nil | |
1.9.3-p194 :049 > colors.rest.rest.first.rest.rest.rest.rest.rest.rest.rest == nil? | |
=> false | |
1.9.3-p194 :050 > colors.rest.rest.first.rest.rest.rest.rest.rest.rest.rest.nil? | |
=> true | |
1.9.3-p194 :051 > nil? | |
=> false | |
1.9.3-p194 :052 > self.nil? | |
=> false | |
1.9.3-p194 :053 > self | |
=> main | |
1.9.3-p194 :054 > self.class | |
=> Object | |
1.9.3-p194 :055 > self.inspect | |
=> "main" | |
1.9.3-p194 :056 > to_s | |
=> "main" | |
1.9.3-p194 :057 > girls | |
=> ["sasha", "jenna", "krystal", "breanna", "jade", "nikki", "sara", "terry", "poppy"] | |
1.9.3-p194 :058 > boys | |
=> ["jarry", "larry", "parry", "gary"] | |
1.9.3-p194 :059 > colors | |
=> [["light1", "light2", "light3", "light4"], ["med1", "med2", "med", "med4", "med5"], ["coal", "charcoal", "slate", "rust", "maroon", "ebony"]] | |
1.9.3-p194 :060 > lights | |
=> ["light1", "light2", "light3", "light4"] | |
1.9.3-p194 :061 > darks | |
=> ["coal", "charcoal", "slate", "rust", "maroon", "ebony"] | |
1.9.3-p194 :062 > mediums | |
=> ["med1", "med2", "med", "med4", "med5"] | |
1.9.3-p194 :063 > colors.length | |
=> 3 | |
1.9.3-p194 :064 > colors.count | |
=> 3 | |
1.9.3-p194 :065 > colors.size | |
=> 3 | |
1.9.3-p194 :066 > colors.kind_of | |
NoMethodError: undefined method `kind_of' for #<Array:0x007fab2c939318> | |
from (irb):66 | |
from /Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>' | |
1.9.3-p194 :067 > colors.kind_of?(Array) | |
=> true | |
1.9.3-p194 :068 > colors.kind_of?(Array)a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.syntax-highlighting.com/p/show?id=5352 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment