Ruby - Metaprogramming Fundamentals
Which of the following is the correct syntax to create a new class with
Class.new and add a method greet that returns "Hello"?Class.new and add a method greet that returns "Hello"?def method_name; ...; end.greet returning "Hello". MyClass = Class.new do def greet return "Hello" end end is correct syntax but missing the 'end' for the block in MyClass = Class.new do def greet return "Hello" end end, so MyClass = Class.new do def greet return "Hello" end end is invalid as given. MyClass = Class.new { greet() = "Hello" } uses invalid method syntax. MyClass = Class.new { def greet() puts "Hello" } uses puts which prints but does not return the string.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions