<< Previous Page
    

    
      Table of Contents
    

    
      Next Page >>
    
  
07
%q{Set Operations}

# Create a set
Set[1,1,2,3,4,5,6,6]
=> #<Set: {1, 2, 3, 4, 5, 6}>

# Union of two sets
Set[1,2,3] | [3,4,5]
=> #<Set: {1, 2, 3, 4, 5}>

# Difference between sets
Set[1,2,3,1,2] - [1,4]
=> #<Set: {2, 3}>

# Intersection between sets
Set[1,2,3,1,2] & [1,4]
=> #<Set: {1}>

# Exclusion between sets
Set[1,2,3,1,2] ^ [1,4]
=> #<Set: {4, 2, 3}>

# Add to set
Set[1,2,3] << 4
=> #<Set: {1, 2, 3, 4}>

# Superset
Set[1,2,3,4] > Set[2,3]
=> true

# Subset
Set[2,3] < Set[1,2,3,4]
=> true

%q{Hash Operations}

# Superset
{a: 5, b: 6} > {a: 5}
=> true

# Subset
{a: 5} < {a: 5, b: 6}
=> true

%q{String Operations}
%q{Array Operations}

# Make array unique
[1,1,2,3,4,5,6,6].uniq
=> [1, 2, 3, 4, 5, 6]

# Union of two arrays
[1,2,3] | [3,4,5]
=> [1, 2, 3, 4, 5]

# Difference between arrays
[1,2,3,1,2] - [1,4]
=> [2, 3, 2]

# Intersection between arrays
[1,2,3,1,2] & [1,4]
=> [1]

# Add to array
[1,2,3] << 4
=> [1, 2, 3, 4]

# Multiply an array
[1,2,3] * 3
=> [1, 2, 3, 1, 2, 3, 1, 2, 3]

# Concatenate into string
[1,2,3] * ","
=> "1,2,3"

# Convert object to array
Array({ a: "1", b: "2" })
=> [[:a, "1"], [:b, "2"]]

# Array with given size
Array.new(3)
=> [nil, nil, nil]

# Array with default values
Array.new(3, "default")
=> ["default", "default", "default"]

# Array with block as default
Array.new(3) { |i| i.to_s }
=> ["0", "1", "2"]


'abc' > 'ac'
=> true

'ac' < 'abc'
=> true

'pew' * 3
=> "pewpewpew"
'abc' >= 'ac'
=> true

'ac' <= 'abc'
=> true

'42'.rjust(8, '0')
=> "00000042"
'abc' >= 'abc'
=> true

'abc' > 'abc'
=> false

'63'.ljust(8, 'x')
=> "63xxxxxx"
07
    
      << Previous Page
    

    
      Table of Contents
    

    
      Next Page >>