Skip to content

Instantly share code, notes, and snippets.

@eladmeidar
Created April 13, 2014 15:53
Show Gist options
  • Save eladmeidar/10589711 to your computer and use it in GitHub Desktop.
Save eladmeidar/10589711 to your computer and use it in GitHub Desktop.
# Add numbers 4 and 5
# Print "Hello"
# Write an expression that evaluates to whatever was stored in variable x
# Write an experssion that evaluates to whatever was in x plus 1
# Write an expression that evaluates to true if x is greater than 5 and evaluates to false otherwise
# Write a condition that prints "hello" if variable "person" is a symbol :friend and does nothing otherwise
# Write a condition that prints "enough" if x is greater than 100 and prints "not enough" otherwise
# Write a condition that returns "good morning" when "hour < 12" and "good afternoon" when "hour >= 12"
# Define a method named "method" that takes no arguments
# Define a method named "foo" that takes one argument named "arg"
# Define a method named "some_method" that takes two arguments, first named "x", second named "y"
# Define a method named "alive?" that takes no arguments and always returns true
# Define a method named "first" that takes two arguments and returns the first one
# Define a method named "second" that takes two arguments and returns the second one
# Define a method named "sum" that takes two arguments and returns sum of both
# Define a class named "Car"
# Define a class named "Person" with getter and setter for attribute "name"
# Define a class named "Book" with getter and setter for two attributes "title" and "author"
# Extend a class "String" with a method "myself" that returns the string itself
# Extend a class "String" with a method "is_blank?" that returns true if the string == "" and false otherwise
# Call a method named "callme" passing no argument
# Call a method named "x" passing no argument
# Call a method named "puts" passing one string argument "Hello"
# Call a method named "to_s" on a number 123
# Call a method named "join" on array ['hello', 'world'] with one string argument " "
# Assign number 42 to a variable named "x"
# Assign result of adding 2 to 3 to a variable named "sum"
# Assign the result of calling method "to_s" on a number 123 to a variable "s"
# Assign a string "John" to an instance variable called "name"
# Interpolate number 123 into a string, so that the result is "my number is 123"
# Given array stored in variable "arr" retrieve its first element
# Given array stored in variable "a" retrieve its second element
# Given array stored in variable "strings" retrieve its last element
# Given array stored in variable "numbers" calculate a sum of its first and last element
# Make a new instance of class "User"
# Make a new instance of class "BlogPost" and assign it to a variable "post"
# Make a new instance of class "CreditCard" passing 10_000 as an argument to the initializer
# Define a class named "Computer" with an initializer that takes two arguments: called "cpu" and "ram"
# Define a class named "Song" with a class method named "all" that takes no arguments
# Define a class named "Artist" with a class method named "find" that takes one argument "name"
# Call a method named "each" on an array "a", passing a block that takes an argument called "e" and prints it
# Call a method named "upto" on a number 0, passing 10 as an argument and a block that takes one argument and prints it
# Print all elements in an array ['Alex', 'Bob', 'Cecil'], each in a separate line
# Interpolate variable "index" in a string, so that the result is "now at VALUE_OF_INDEX"
# Interpolate variables "index" and "element" in a string, so that the result is "value under VALUE_OF_INDEX is VALUE_OF_ELEMENT"
# Given an array stored in variable "words" call method "capitalize!" on its first element
# Given an array stored in variable "names" call method "empty?" on its second element
# Given a hash stored in variable "book_index" retrieve a value under key "name" (string)
# Given a hash stored in variable "phone_book" retrieve a value under key :police (symbol)
# Given a hash stored in variable "locations" store value "41'51N 87'39W" under key :chicago
# Given a hash stored in variable "prices" retrieve an array of keys
# Given a hash stored in variable "company", assuming its values are strings, retrieve first character of value under key :ceo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment