FlashKeepers

PHP and Ruby · College · College and University

Ruby I: Syntax and Objects

Ruby types, symbols, strings, arrays, hashes, blocks, procs, classes, modules and mixins.

About this set

39 basic cards for College PHP and Ruby. Set 1 of 2 in Ruby. It opens with "What are the main primitive data types in Ruby?" and "How do you create a symbol in Ruby?". Study it alongside the other College sets below.

39 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What are the main primitive data types in Ruby?
Show answerInteger, Float, String, Symbol, Boolean (true/false), and nil
How do you create a symbol in Ruby?
Show answerPrecede an identifier with a colon: :symbol_name
What is the key difference between a symbol and a string?
Show answerSymbols are immutable and reused in memory; strings are mutable and create new objects each time
How do you interpolate a variable into a double-quoted string in Ruby?
Show answerWrap the variable in #{}: "Hello, #{name}"
What does the .to_s method do?
Show answerConverts an object to its string representation
How do you create an array in Ruby?
Show answerUse square brackets: [1, 2, 3] or call Array.new
How do you access the first element of an array?
Show answerUse index 0 or call .first: array[0] or array.first
How do you access the last element of an array?
Show answerUse index -1 or call .last: array[-1] or array.last
How do you add an element to the end of an array?
Show answerUse .push or the << operator: array.push(x) or array << x
What does the .pop method do to an array?
Show answerRemoves and returns the last element
What is the key difference between an array and a hash?
Show answerArrays use numeric indices (0, 1, 2, ...); hashes use any object as a key
How do you create a hash in Ruby?
Show answerUse curly braces with key-value pairs: {key: value} or {"key" => value}
How do you access a value in a hash?
Show answerUse square brackets with the key: hash[:key]
Are symbols commonly used as hash keys?
Show answerYes, symbols are the standard choice: {name: "John", age: 30}
What does the .each method do?
Show answerIterates over each element in a collection and runs a block for each

24 more cards in the app

Study this set free