Ruby - Class Methods and VariablesWhich of the following is the correct syntax to define a constant named MAX_SPEED with value 100 inside a Ruby class?Adef MAX_SPEED; 100; endBmax_speed = 100Cconst MAX_SPEED = 100DMAX_SPEED = 100Check Answer
Step-by-Step SolutionSolution:Step 1: Identify Ruby constant naming rulesConstants start with an uppercase letter and are assigned with =.Step 2: Check syntax optionsOnly 'MAX_SPEED = 100' matches Ruby constant syntax.Final Answer:MAX_SPEED = 100 -> Option DQuick Check:Constant syntax = uppercase name + = [OK]Quick Trick: Constants start with uppercase letters and use = [OK]Common Mistakes:Using lowercase names for constantsTrying to use 'const' keyword (not Ruby)Defining constants as methods
Master "Class Methods and Variables" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Blocks, Procs, and Lambdas - Block parameters - Quiz 15hard Blocks, Procs, and Lambdas - Why blocks are fundamental to Ruby - Quiz 10hard Blocks, Procs, and Lambdas - Why blocks are fundamental to Ruby - Quiz 9hard Class Methods and Variables - Class variables (@@) and their dangers - Quiz 1easy Classes and Objects - Initialize method as constructor - Quiz 13medium Classes and Objects - Instance variables (@) - Quiz 5medium Enumerable and Collection Processing - Any?, all?, none? predicates - Quiz 8hard Enumerable and Collection Processing - Sort_by for custom sorting - Quiz 14medium Error Handling - Begin/rescue/end blocks - Quiz 4medium Modules and Mixins - Custom modules as mixins - Quiz 14medium