How come in Ruby it’s possible to directly have an if statement directly in the class declaration? AKA:
class ApplicationController < ActionController::Base
if foo
bar = "x"
end
end
I know there is some class instance variables, since the Class inherits from Object, is it the same thing?
I just need some clarification about this whole thing 🙂
Thanks!
The body of a class declaration is code just like everything else in Ruby. That’s how you can use methods like
attr_accessor,privateandinclude— those are all just methods of the class. It’s part of Ruby’s philosophy of pervasive object orientation.