Skip to content

Instantly share code, notes, and snippets.

@Rubiromi
Forked from jwoertink/ruby_quiz_1.md
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rubiromi/d8ec3c34b65ac38ae538 to your computer and use it in GitHub Desktop.
Save Rubiromi/d8ec3c34b65ac38ae538 to your computer and use it in GitHub Desktop.
  1. What is the difference between a local variable, and an instance variable?

local variable only passes in a same block. instant variable passes between blocks in the same class and we name it with @ in beginning.

  1. What is the datatype of "DevPoint Labs"?

String

  1. Assign the number 10 to the local variable n.

n = 10

  1. Assign your name to the local variable name.

name = "Hiromi"

  1. What is an Array?

group of data, each assigned to index start with 0.

  1. Give an example of when you’d use an Array.

When I list up names of classmates.

  1. What is a method?

A method is simply a definition of an action that can be performed on an object.

  1. Name 3 iterator methods for an Array.

array = ["a", "b", "c"] array = w%(a, b, c)

array = [] array << 'a'

array = [] array.push('a')

  1. Name 3 methods for a String.

.reverse .split .upcase

  1. What datatype does 5 / 2 return?

fixnum

  1. What is a Hash?

It is a data set too, but assigned to keys instead of index numbers.

  1. Give an example of when you’d use a Hash.

When I want to save customer information including their names, phone numbers, ages, etc.

  1. What is a class?

It is like a container to keep related methods in.

  1. True or False; A class is a constant.

True

  1. true and false are called what?

Boolean

  1. Write 4 conditional operators.

if case boolean (true/false) when

  1. Create a method called bucket that returns an empty array.

def bucket(things = []) puts "#{things}" end

  1. Name 6 ruby special keywords. (a keyword is a word that already has a special meaning)

do, insert, break, yield, class, end

  1. How would you convert a number into a string?

.to_s

  1. How would you convert a string into a number?

.to_i

  1. What is class inheritance?

insert all the methods from one class to another class.

  1. What are modules used for?

You use modules to define common methods that could be included in other class definition.

  1. What is a gem?

It is a Ruby library. Gems are pre-coded programs you can install and use it on your code.

  1. Name 4 gems, and their purposes.

pry = I can use like irb, or use for debugging. sinatra = It is like a template to create website. rvm = use it for Ruby version control coffee-script = It is a bridge to the JS CoffeeScript compiler.

  1. What are comments used for in programming?

use with # in beginning and insert some messages to yourself, or to other developers.

  1. In Ruby, only 2 things evaluate to false. What are they?

false and nil

  1. Write 2 comparison operators.

5 >= 3 6 / 3 == 4 / 2

  1. Write the code for “ if dave’s age is greater than or equal to 21”

d = "dave's age".to_i

if d >= 21 end

  1. Instantiate a Car class.

class Car end

  1. What is a method chain?

You add a method after another method.

ex. "string".upcase.reverse

  1. How would you capitalize and reverse a string then print it out to the console?

puts "string".capitalize.reverse

  1. What is a method to add an object to an array?

push

  1. How would you add an object to a hash?

hash = {} hash[:key] = "value"

  1. What are 2 valid datatypes of keys for a hash?

'string' or :symbol

  1. What is a writer method?

attr_writer

  1. What is a reader method?

attr_reader method takes a string as an argument, and defines a method.

  1. There are 4 types of variables. What are they?

local variables instant variables class variables Global variables

  1. What does the question mark at the end of a method in ruby mean?

Is it true or false?

  1. What’s a common way to debug your code?
  1. Use pry.
  2. Search on Google.
  3. use inspect
  1. How would you return the string "two" from this array? arr = ["one", "two", "three"]

puts "#{arr[1]}"

  1. How would you return the string "DevPoint" from this hash? hsh = {:name => "DevPoint"}

puts "#{hsh[:name]}"

  1. What is the datatype for :age?

symbol

  1. What is the datatype for -36.98?

float

  1. What is the datatype for [1, 2, 3]?

array

  1. What is the datatype for "BOOM goes the dynamite"?

string

  1. What is the datatype for 123412?

fixnum

  1. What is the datatype for {:food => "burger"}?

hash

  1. What is the datatype for false?

Boolean

  1. What is the purpose of nil?

It means value is no-defined.

  1. How would you print out the current date?

Time.new

  1. How would you print out just the current year without using a Fixnum?

Time.now.year.to_s

  1. What is String interpolation?

I can't explain with words really good, but it is like:

name = "Hiromi" puts {My name is #{name}.}

to insert some value into a string.

  1. What is String concatenation?

It is like: name = "Hiromi" "Hello. My name is " + name = " ."

to connect strings.

  1. What does OOP stand for?

Object Oriented Programming

  1. What does instantiation mean?

To create something.

  1. What is the name of the method that is called every time an object is instantiated?

instant method

  1. What are arguments?

** I asked about arguments so many time to make you sick, but I guess I still can't explane **

  1. How do you pass an argument?

def some_method('name', 'age') end

  1. Write a method called eat that has an argument food with a default value of "cheese".

def eat('food' = "cheese") end

  1. What is a loop?

Repeat a method under some fixed condition.

  1. How long has ruby been around?

About 20 years

  1. How are you doing on this quiz so far?

Not really good. My problems are not just with Ruby, but with English too. It takes time to understand what it really asking me for...

  1. Is anyone else hungry?

Not me. I had some Sushi for lunch :)

  1. What are the pipe characters used for in a block?

They are the variables yielded to the block.

  1. What is the difference between single quote strings and double quote strings?

Usually you can use either of them. However, if you use string interpolation, you have to use double quote. And, if you have to use single quote to 'quote' something in a string, instead of using ', it easier to use " ".

  1. Name some rules for naming a method?

It can't be started with numbers. It have to start with lowercase letter. Words are connected with under score.

  1. How can you tell if a method is an instance or class method?

If method name starts with lower case letter, it is instance method. If method name starts with up case letter, it is class method.

  1. In an instance method, what is self?

self inside a class method is the class itself.

  1. How do you add a dependency to a file?

type: require "file name"

** I hope I understood the question right. **

  1. I have a text file called names.txt. Each name is on it's own line. How would you print all the names in the file?

f = File.open("name.txt") name = File.open('name.txt') {|f| f.gets.chomp } puts "#{name}"

** to be honest, I have no clue on this question. **

  1. When a method defines an argument that has a asterisk in front of a variable name, what is that asterisk referred to? e.g. def thing(*stuff)

The list of parameters passed to an object is, in fact, available as a list. To do this, we use what is called the splat operator - which is just an asterisk (*). ... with my word, "You can call the method with any number of arguments (including none)".

  1. When a method defines an argument that has an ampersand in front of a variable name, what is that ampersand and variable name collectivly called? e.g. def thing(&stuff)

The & calls to_proc on the object, and passes it as a block to the method. These two calls are equivalent.

  1. What is it called when you see the do and end keywords together?

block

  1. What does DRY stand for?

Don't Repeat Yourself

  1. What does DSL stand for?

Domain Specific Language

  1. This question left blank intentionally.

  2. What does MRI stand for?

Matz's Ruby Interpreter

  1. What is the difference between JRuby and MRI?

JRuby is an implementation of the Ruby programming language atop the Java Virtual Machine, written largely in Java. MRI is a series of ruby interpreters. This is the original, canonical implementation of Ruby from which the standards (ruby-spec) are being extracted.

  1. What would you use RubyMotion for?

RubyMotion apps are created and later maintained from the terminal command-line. A RubyMotion project is based on the Rake tool and can be configured by editing its Rakefile.

Hmm. It's nice to know.

  1. Does your head hurt?

No, but I'm about to puke.

@jwoertink
Copy link

8- An iterator method is a method that allows you to iterate over a collection to perform an action on each element in the array.
29- This defines a class, but doesn't actually instantiate it
56- Anytime you instantiate an object with SomeClass.new, there is a method that gets called every time. What is that method?
80- please don't puke up that sushi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment