Complete the code to print the current object using self.
puts [1]In Ruby, self refers to the current object. Using puts self prints that object.
Complete the method to return the class of the current object using self.
def get_class [1].class end
The keyword self refers to the current object, so self.class returns its class.
Fix the error by replacing the blank with the correct keyword to call a method on the current object.
def greet [1].say_hello end
To call a method on the current object, use self. Other options are not valid Ruby keywords.
Fill the blank to define a class method using self.
class Person def [1].greet puts "Hello!" end end
Class methods are defined by prefixing the method name with self. inside the class.
Fill all three blanks to complete the code that prints the object id using self inside an instance method.
class Item def print_id id = [1].[2] puts "ID: [3]" end end
Inside an instance method, self.object_id gets the object's id. To print it inside a string, use string interpolation #{id}.