Ruby

Card Set Information

Author:
ericburger
ID:
277895
Filename:
Ruby
Updated:
2014-07-02 06:17:18
Tags:
Ruby
Folders:

Description:
Introduction to Ruby, Control Flow, Looping
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user ericburger on FreezingBlue Flashcards. What would you like to do?


  1. Data types
    • numbers (no quotes)
    • boolean (no quotes)
    • strings (quotes)

    case-sensitive
  2. Variable
    • my_num = 100
    • (single equal sign)
  3. Six arithmetic operators
    • +
    • -
    • *
    • /
    • ** - Exponentiation
    • % - Modulo
  4. puts
    print
    • put string - adds a new blank line
    • print
  5. editor - interpreter - console
    type code in editor - interpreter reads - console shows result
  6. String Methods
    .length
    .reverse
    .upcase
    .downcase
    .capitalize
    .include? "x"
    .gsub!(/x/, "y")
    .split (" ")
    • "Eric".length - length of string: 4
    • "Eric".reverse - "cirE"
    • "Eric".upcase - "ERIC"
    • "Eric".downcase - "eric"
    • capitalize
    • does it include x?
    • global substitution
    • splits at delimiter
  7. Comments
    #
    =begin
    =end
    • # single-line comment
    • =begin
    • multi-line-
    • comment
    • =end
  8. Naming Convention: Local Variables
    • name =
    • my_name =
  9. Chained Method
    • name = "Eric"
    • name.downcase.reverse.upcase
  10. gets.chomp
    • print "What's your first name?
    • "first_name = gets.chomp

    • gets - gets input from user
    • chomp - deletes blank line (newline) that is automatically inserted when ruby gets data
  11. String Interpolation #{x}
    • x = monkey
    • print "Curious George is a #{x}"
  12. ! method
    • print "What's your first name?"
    • first_name = gets.chomp
    • first_name.capitalize!

    ! changes value of variable - next time you use that variable, the !-version will be used
  13. if
    elsif
    else
    end
    • if 3 < 4   
    • puts "3 is smaller than 4"
    • elsif 3 > 4   
    • puts "nope"
    • else    puts
    • "I won't get printed anyways"
    • end
  14. unless
    else
    end
    • hungry = false
    • unless hungry 
    • puts "I'm writing Ruby programs!"
    • else  puts "Time to eat!"
    • end

    • a = 4
    • print "Good to Go" unless a == 5
  15. Comparators (Relational Operators)
    !=
    ==
    >=
    <=
    <
    >
    • not equal
    • equal
  16. Logical/Boolean Operators
    &&
    ||
    !
    • and (true && true: true, true && anything else:false)
    • or (false || false: false, false || anything else: true)
    • not
  17. while
    end
    • counter = 1
    • while counter < 11 
    • puts counter 
    • counter = counter + 1
    • end
  18. until
    • i = 0
    • until i == 6
    • i += 1
    • end
    • puts i
  19. Assignment operators
    +=
    -=
    *=
    /=
    • increment by
    • decrease by
    • multiply by
    • divide by
  20. for
    end
    • for num in 1...10 
    • puts num
    • end
  21. Inclusive and Exclusive Ranges
    ..
    ...
    • .. inclusive
    • ... exclusive
  22. loop do
    break if
    end
    • i = 0
    • loop do
    • i += 1
    • print "#{i}"
    • break if i > 5
    • end
  23. for
    next if
    print
    end
    • for i in 1..5
    • next if i % 2 == 0
    • print i
    • end
  24. array.each do |x|
    x +=
    print "#{x}"
    end
    my_array = [1, 2, 3]

    • array = [1,2,3,4,5]
    • array.each do |x| 
    • x += 10 
    • print "#{x}"
    • end
  25. .times
    3.times {print "I love you"}

What would you like to do?

Home > Flashcards > Print Preview