Hi All,
The assignment from last week's class was to create a method that will produce an array of 10 unique random integers between 1 and 10.
We will go over this assignment during the class on June 29th.
Thanks,
Glenn
Sunday, June 28, 2009
Answers to Ruby Review #3
What is the Ruby object that's a number but not an integer called?
Numbers that aren't integers are called floats.
What's the syntax of the Ruby case statement?
case x
   when 5 then puts 'x == 5'
   when 15 then puts 'x == 15'
   when 10 then puts 'x == 10'
   else puts "I don't know what x is equal to."
end
What happens if more than one of the statements within a case statement evaluates to true?
The first one is executed.
What objects can be stored in a Ruby array?
Any object can be stored in a Ruby array.
What is an iterator?
An iterator is a method that acts essentially like a loop.
What is a block?
A block is code that follows a method and intereacts with the code in the method.
What is the difference between a block that uses 'do' and 'end' and a block that uses '{' and '}'?
While there are differences, these differences are not important when you are first learning Ruby.
How do you pass a value into a method?
You create a method that accepts a value by adding a variable name (or names) within the parentheses following the method name on the def line. If a pre-defined method accepts a parameter (or parameters) they can be added following the method call (the parenthesis are usually optional).
How do you pass a value from a method into a block?
You pass control of execution fro the method to the block vi the yield method. You can pass an object from the method to the block by including that object after the yield method call. In this case as well, the parentheses are optional.
Numbers that aren't integers are called floats.
What's the syntax of the Ruby case statement?
case x
   when 5 then puts 'x == 5'
   when 15 then puts 'x == 15'
   when 10 then puts 'x == 10'
   else puts "I don't know what x is equal to."
end
What happens if more than one of the statements within a case statement evaluates to true?
The first one is executed.
What objects can be stored in a Ruby array?
Any object can be stored in a Ruby array.
What is an iterator?
An iterator is a method that acts essentially like a loop.
What is a block?
A block is code that follows a method and intereacts with the code in the method.
What is the difference between a block that uses 'do' and 'end' and a block that uses '{' and '}'?
While there are differences, these differences are not important when you are first learning Ruby.
How do you pass a value into a method?
You create a method that accepts a value by adding a variable name (or names) within the parentheses following the method name on the def line. If a pre-defined method accepts a parameter (or parameters) they can be added following the method call (the parenthesis are usually optional).
How do you pass a value from a method into a block?
You pass control of execution fro the method to the block vi the yield method. You can pass an object from the method to the block by including that object after the yield method call. In this case as well, the parentheses are optional.
Saturday, June 20, 2009
Answers to Ruby Review #2
What does dynamic typing mean?
Dynamic typing means that you don't have the declare the type, or class, of a variable before using it.
What does static typing mean?
Static typing means that you do have to declare the type of every variable.
Which kind of language is Ruby?
Ruby is a dynamically typed language.
What is string interpolation?
String interpolation is the process of inserting the value of a variable into a string that is defined with double quotes.
For example:
name = 'Glenn'
puts "My name is #{name}." # My name is Glenn.
How do you increment numbers in Ruby?
You increment numbers with +=. You can do analogous actions with -=, *= and /=.
For example:
x = 10
x += 2
puts x # writes 12 to the console
What's the difference between a Fixnum and a Bignum?
Finums are relatively small integers and Bignums relatively big ones.
For example:
puts 10.class # Fixnum
puts 10000000000.class # Bignum
How do you convert from a number to an string?
Use the to_s method on the number.
For example:
puts 10.to_s.class # String
How do you convert from a string to a number?
Use the to_i method.
For example:
puts '10'.to_i.class # Fixnum
If you try this on a string that can't be converted to a number, you get 0.
puts 'cat'.to_i # 0
What are three ways to loop in Ruby?
while, until and for.
What is the Ruby syntax for if-then-else?
x = 10
if x < 10
   puts 'x < 10'
elsif x > 10
   puts 'x > 10'
else
   puts 'x == 10'
end
Can you write an if-then on a single line?
Yes.
x = 10
puts 'x == 10' if x == 10 # x == 10
if x == 10 then puts 'x == 10' end # x == 10
The first example is far more common in Ruby.
Can you write an if-then-else on a single line?
Yes, by using the ternary operator.
x = 10
x == 10 ? (puts 'x == 10') : (puts 'x != 10') # x == 10
How do you take a slice out of a string?
puts 'Glenn'.slice(1, 2) # le
puts 'Glenn'.slice(-1, 1) # n
How do you reverse a string?
puts 'Glenn'.reverse # nnelG
What does the term 'receiver' mean?
The object on which the method is called.
What does the term 'destructive method' mean?
A method that changes the value of the receiver.
Are all methods that end in a '!' destructive methods?
No. But usually that is the case. This is a Ruby convention. It is not enforced by the Ruby interpretor.
Name the 2 Boolean objects.
The 2 Ruby Boolean objects are true and false.
What method does the puts method call on every parameter passed to it?
puts always calls the to_s method on objects that are passed to it.
What is the syntax of a Ruby case?
x = 10
case x
   when 5 then puts 'x == 5'
   when 15 then puts 'x == 15'
   when 10 then puts 'x == 10'
   else puts "I don't know what x is equal to."
end
Dynamic typing means that you don't have the declare the type, or class, of a variable before using it.
What does static typing mean?
Static typing means that you do have to declare the type of every variable.
Which kind of language is Ruby?
Ruby is a dynamically typed language.
What is string interpolation?
String interpolation is the process of inserting the value of a variable into a string that is defined with double quotes.
For example:
name = 'Glenn'
puts "My name is #{name}." # My name is Glenn.
How do you increment numbers in Ruby?
You increment numbers with +=. You can do analogous actions with -=, *= and /=.
For example:
x = 10
x += 2
puts x # writes 12 to the console
What's the difference between a Fixnum and a Bignum?
Finums are relatively small integers and Bignums relatively big ones.
For example:
puts 10.class # Fixnum
puts 10000000000.class # Bignum
How do you convert from a number to an string?
Use the to_s method on the number.
For example:
puts 10.to_s.class # String
How do you convert from a string to a number?
Use the to_i method.
For example:
puts '10'.to_i.class # Fixnum
If you try this on a string that can't be converted to a number, you get 0.
puts 'cat'.to_i # 0
What are three ways to loop in Ruby?
while, until and for.
What is the Ruby syntax for if-then-else?
x = 10
if x < 10
   puts 'x < 10'
elsif x > 10
   puts 'x > 10'
else
   puts 'x == 10'
end
Can you write an if-then on a single line?
Yes.
x = 10
puts 'x == 10' if x == 10 # x == 10
if x == 10 then puts 'x == 10' end # x == 10
The first example is far more common in Ruby.
Can you write an if-then-else on a single line?
Yes, by using the ternary operator.
x = 10
x == 10 ? (puts 'x == 10') : (puts 'x != 10') # x == 10
How do you take a slice out of a string?
puts 'Glenn'.slice(1, 2) # le
puts 'Glenn'.slice(-1, 1) # n
How do you reverse a string?
puts 'Glenn'.reverse # nnelG
What does the term 'receiver' mean?
The object on which the method is called.
What does the term 'destructive method' mean?
A method that changes the value of the receiver.
Are all methods that end in a '!' destructive methods?
No. But usually that is the case. This is a Ruby convention. It is not enforced by the Ruby interpretor.
Name the 2 Boolean objects.
The 2 Ruby Boolean objects are true and false.
What method does the puts method call on every parameter passed to it?
puts always calls the to_s method on objects that are passed to it.
What is the syntax of a Ruby case?
x = 10
case x
   when 5 then puts 'x == 5'
   when 15 then puts 'x == 15'
   when 10 then puts 'x == 10'
   else puts "I don't know what x is equal to."
end
Ruby Review #3
Ruby Course
Brookline Adult and Community Education
June 22, 2009
Review #3
What is the Ruby object that's a number but not an integer called?
What's the syntax of the Ruby case statement?
What happens if more than one of the statements within a case statement evaluates to true?
What objects can be stored in a Ruby array?
What is an iterator?
What is a block?
What is the difference between a block that uses 'do' and 'end' and a block that uses '{' and '}'?
How do you pass a value into a method?
How do you pass a value from a method into a block?
Brookline Adult and Community Education
June 22, 2009
Review #3
What is the Ruby object that's a number but not an integer called?
What's the syntax of the Ruby case statement?
What happens if more than one of the statements within a case statement evaluates to true?
What objects can be stored in a Ruby array?
What is an iterator?
What is a block?
What is the difference between a block that uses 'do' and 'end' and a block that uses '{' and '}'?
How do you pass a value into a method?
How do you pass a value from a method into a block?
Sunday, June 14, 2009
Answers to BACE Ruby Review #1
When was Ruby created?
Ruby was created in 1995, the same year that Java was created.
Who created it?
Yukihiro Matsumoto, known as "Matz" in the Ruby community.
Is Ruby an interpreted language or a compiled language?
Interpreted.
What's the difference?
Interpreted language do not need to be compiled, they are just executed.
What can you use irb for?
Interactive Ruby is good for testing small pieces of code.
How much does Ruby cost?
Ruby is free.
How can you tell which version of Ruby is installed on a computer?
Execute ruby -v at the command prompt.
What are the 'nouns' of object oriented programming called?
Objects.
What are the 'verbs' called?
Methods.
Name three Ruby classes that we talked about last week.
String, Fixnum and Bignum.
Name three methods.
puts, class, methods.
What are all methods called on?
All methods -- even puts -- are called on objects.
What do all methods return?
All methods return objects; sometimes the returnd object is meaningful and sometimes it isn't.
What does the nil object mean?
The absence of anything.
What is an array?
An array is a collection of objects.
What are two ways to create a String object?
s = 'cat'
s = String.new('cat')
What are two ways to create a Fixnum object?
n = 10
n = String.new(10)
What are two great reasons for learning Ruby?
It's compact and it can be fun.
What is the difference between the puts method and the print method?
puts inserts a new line character at the end of the string and print doesn't.
What is the popular Web development that's written in Ruby called?
Ruby on Rails, usually just called Rails.
Ruby was created in 1995, the same year that Java was created.
Who created it?
Yukihiro Matsumoto, known as "Matz" in the Ruby community.
Is Ruby an interpreted language or a compiled language?
Interpreted.
What's the difference?
Interpreted language do not need to be compiled, they are just executed.
What can you use irb for?
Interactive Ruby is good for testing small pieces of code.
How much does Ruby cost?
Ruby is free.
How can you tell which version of Ruby is installed on a computer?
Execute ruby -v at the command prompt.
What are the 'nouns' of object oriented programming called?
Objects.
What are the 'verbs' called?
Methods.
Name three Ruby classes that we talked about last week.
String, Fixnum and Bignum.
Name three methods.
puts, class, methods.
What are all methods called on?
All methods -- even puts -- are called on objects.
What do all methods return?
All methods return objects; sometimes the returnd object is meaningful and sometimes it isn't.
What does the nil object mean?
The absence of anything.
What is an array?
An array is a collection of objects.
What are two ways to create a String object?
s = 'cat'
s = String.new('cat')
What are two ways to create a Fixnum object?
n = 10
n = String.new(10)
What are two great reasons for learning Ruby?
It's compact and it can be fun.
What is the difference between the puts method and the print method?
puts inserts a new line character at the end of the string and print doesn't.
What is the popular Web development that's written in Ruby called?
Ruby on Rails, usually just called Rails.
Wednesday, June 10, 2009
Ruby Review #2
Ruby Course
Brookline Adult and Community Education
June 15, 2009
Review #2
What does dynamic typing mean?
What does static typing mean?
Which kind of language is Ruby?
What is string interpolation?
How do you increment numbers in Ruby?
What's the difference between a Fixnum and a Bignum?
How do you convert from a number to an string?
How do you convert from a string to a number?
What are three ways to loop in Ruby?
What is the Ruby syntax for if-then-else?
Can you write an if-then on a single line?
Can you write an if-then-else on a single line?
How do you take a slice out of a string?
How do you reverse a string?
What does the term 'receiver' mean?
What does the term 'destructive method' mean?
Are all methods that end in a '!' destructive methods?
Name the 2 Boolean objects.
What method does the puts method call on every parameter passed to it?
What is the syntax of a Ruby case?
Brookline Adult and Community Education
June 15, 2009
Review #2
What does dynamic typing mean?
What does static typing mean?
Which kind of language is Ruby?
What is string interpolation?
How do you increment numbers in Ruby?
What's the difference between a Fixnum and a Bignum?
How do you convert from a number to an string?
How do you convert from a string to a number?
What are three ways to loop in Ruby?
What is the Ruby syntax for if-then-else?
Can you write an if-then on a single line?
Can you write an if-then-else on a single line?
How do you take a slice out of a string?
How do you reverse a string?
What does the term 'receiver' mean?
What does the term 'destructive method' mean?
Are all methods that end in a '!' destructive methods?
Name the 2 Boolean objects.
What method does the puts method call on every parameter passed to it?
What is the syntax of a Ruby case?
Syllabus
Introduction to Computer Programming with Ruby
Course Outline
Brookline Adult & Community Education
June 1, 2009 – July 20, 2009
6:30 – 8:30 p.m.
Week 1, June 1: What is Object-Oriented Programming?
Reading: RVQG, Chapters 1 and 2
Goals of this course
My background
What are two of the defining features of objects?
Brief background of Ruby
Installing Ruby v1.8.6
Interactive Ruby (IRB)
The course textbook: Ruby: Visual QuickStart Guide by Larry Ullman
Week 2, June 8: Strings, Numbers and Flow Control
Reading: RVQG, Chapters 3 and 5
Strings
Numbers
Conditionals
do loops
for loops
Iterators
Week 3, June 15: Collections
Reading: RVQG, Chapter 4
Arrays
Ranges
Hashes
Week 4, June 22: Methods
Reading: RVQG, Chapter 6
Return values of methods
Taking arguments
Object-dot notation
Duck typing
Blocks
Week 5, June 29: Classes
Reading: RVQG, Chapter 7
Classes as blueprints for objects
Classes as objects
Constructors
Instance variables
Making an object out of a class
Modifying existing classes
Creating custom classes
Encapsulation
Week 6, July 6: Inheritance
Reading: RVQG, Chapter 8
What is inheritance?
How is it useful?
Can it be overused?
Single inheritance
Week 7, July 13: Modules
Reading: RVQG, Chapter 9
Mixing functionality into a class
Extending the functionality of an object
Week 8, July 20: Review and Next Steps
Review
Next steps
Course Outline
Brookline Adult & Community Education
June 1, 2009 – July 20, 2009
6:30 – 8:30 p.m.
Week 1, June 1: What is Object-Oriented Programming?
Reading: RVQG, Chapters 1 and 2
Goals of this course
My background
What are two of the defining features of objects?
Brief background of Ruby
Installing Ruby v1.8.6
Interactive Ruby (IRB)
The course textbook: Ruby: Visual QuickStart Guide by Larry Ullman
Week 2, June 8: Strings, Numbers and Flow Control
Reading: RVQG, Chapters 3 and 5
Strings
Numbers
Conditionals
do loops
for loops
Iterators
Week 3, June 15: Collections
Reading: RVQG, Chapter 4
Arrays
Ranges
Hashes
Week 4, June 22: Methods
Reading: RVQG, Chapter 6
Return values of methods
Taking arguments
Object-dot notation
Duck typing
Blocks
Week 5, June 29: Classes
Reading: RVQG, Chapter 7
Classes as blueprints for objects
Classes as objects
Constructors
Instance variables
Making an object out of a class
Modifying existing classes
Creating custom classes
Encapsulation
Week 6, July 6: Inheritance
Reading: RVQG, Chapter 8
What is inheritance?
How is it useful?
Can it be overused?
Single inheritance
Week 7, July 13: Modules
Reading: RVQG, Chapter 9
Mixing functionality into a class
Extending the functionality of an object
Week 8, July 20: Review and Next Steps
Review
Next steps
Friday, June 5, 2009
BACE Ruby Review #1
Hi All,
If you get the chance, please check out the Ruby quiz below.
I plan to have a similar quiz after every class.
Don't worry, this is not like a quiz from back in school. It's not meant to trip you up, and there won't be a grade. It is meant as a review of what we've covered in the course so far.
I will go over the answers at the start of the class next week.
Here you go:
When was Ruby created?
Who created it?
Is Ruby an interpreted language or a compiled language?
What's the difference?
What can you use irb for?
How much does Ruby cost?
How can you tell which version of Ruby is installed on a computer?
What are the 'nouns' of object oriented programming called?
What are the 'verbs' called?
Name three Ruby classes that we talked about last week.
Name three methods.
What are all methods called on?
What do all methods return?
What does the nil object mean?
What is an array?
What are two ways to create a String object?
What are two ways to create a Fixnum object?
What are two great reasons for learning Ruby?
What is the difference between the puts method and the print method?
What is the popular Web development that's written in Ruby called?
See you on Monday June 8th.
Glenn
If you get the chance, please check out the Ruby quiz below.
I plan to have a similar quiz after every class.
Don't worry, this is not like a quiz from back in school. It's not meant to trip you up, and there won't be a grade. It is meant as a review of what we've covered in the course so far.
I will go over the answers at the start of the class next week.
Here you go:
When was Ruby created?
Who created it?
Is Ruby an interpreted language or a compiled language?
What's the difference?
What can you use irb for?
How much does Ruby cost?
How can you tell which version of Ruby is installed on a computer?
What are the 'nouns' of object oriented programming called?
What are the 'verbs' called?
Name three Ruby classes that we talked about last week.
Name three methods.
What are all methods called on?
What do all methods return?
What does the nil object mean?
What is an array?
What are two ways to create a String object?
What are two ways to create a Fixnum object?
What are two great reasons for learning Ruby?
What is the difference between the puts method and the print method?
What is the popular Web development that's written in Ruby called?
See you on Monday June 8th.
Glenn
Wednesday, June 3, 2009
Welcome to BACERuby
Hi All,
Welcome to the BACE (Brookline Adult and Community Education) Ruby blog.
I will be posting regular blogs on our course on assignments, Ruby questions, Ruby tips and more.
Please check the blog regularly for information on the course.
Thanks!
Glenn
Welcome to the BACE (Brookline Adult and Community Education) Ruby blog.
I will be posting regular blogs on our course on assignments, Ruby questions, Ruby tips and more.
Please check the blog regularly for information on the course.
Thanks!
Glenn
Subscribe to:
Comments (Atom)