Skip to content

Instantly share code, notes, and snippets.

@zph
Created December 17, 2012 07:36
Show Gist options
  • Save zph/4316458 to your computer and use it in GitHub Desktop.
Save zph/4316458 to your computer and use it in GitHub Desktop.
# Basic Ruby Primitives
# String
"Test String".upcase.split("S") # => ["TE", "T ", "TRING"]
# Array
a = [1, 2, 3]
a[0..1] # => [1, 2]
# Hash
h = Hash.new # => {}
h.class # => Hash
h.inspect # => "{}"
h.object_id # => 70255624059320
# or h = {}
h = {} # => {}
h.class # => Hash
h.inspect # => "{}"
h.object_id # => 70255624057600
h = {
:name => "Test_name",
:type => 1,
:array => ["bob", 1, {}],
}
h # => {:name=>"Test_name", :type=>1, :array=>["bob", 1, {}]}
h[:array][0] # => "bob"
h[:array][2] # => {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment