1
module Test1 module Test2 def self.included(base) # Where can I declare constant ? How ? base.extend ClassMethods base.class_eval do # named scopes end end end end class abc include Test1::Test2 end 

Where can I declare constant ? How ?

2 Answers 2

7

I'm not sure I understand - did you mean this:

module Test1 module Test2 CONSTANT = 5 def self.included(base) # Where can I declare constant ? How ? base.extend ClassMethods base.class_eval do # named scopes end end module ClassMethods end end end class A include Test1::Test2 end puts A::CONSTANT # => 5 
Sign up to request clarification or add additional context in comments.

Comments

0

In Ruby, a variable that starts with a capital letter, is considered a constant. So, you might use a variable as Pi = 3.14 to declare a constant value.

2 Comments

Not 'starts with' but is all CAPS
@Tim, rookieRailer is correct. Ruby Constants start_with capital letters. Classes are actually constants in Ruby.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.