Ruby

Amount of flashcards: 20

How do you access elements in an array in Ruby?

You can access elements in an array using their index, starting from 0.

How do you add elements to an array in Ruby?

You can add elements to an array using the push or << operator.

How do you define a hash in Ruby?

In Ruby, a hash is defined using the syntax, {key1, value1, key2, value2}.

How do you access values in a hash in Ruby?

You can access values in a hash using their corresponding keys.

What is the difference between a symbol and a string in Ruby?

Symbols are immutable and unique, while strings are mutable and can have multiple instances with the same value.

What is the ternary operator in Ruby?

The ternary operator in Ruby is a shorthand way to write if-else statements, using the syntax, condition ? true_expression , false_expression.

What is the difference between a block and a lambda in Ruby?

A block is a piece of code that can be passed to a method, while a lambda is an object that can be stored in a variable and called later.

What is the purpose of the 'require' keyword in Ruby?

The 'require' keyword is used to load external libraries or files in Ruby.

Prev

2 out of 2

Next
© 2023 - Present Flashio. All rights reserved.