oop - Can I create a method-scoped constant in Ruby? -


i want create constant accessible inside containing method. in other languages 1 might this:

void function() {   const int max = 25;   int array[max];    //do } void function2() {    const int max = 50;    int array[max];    //do else } 

in both methods max not global class. believe in data hiding, , i'd know if there way in ruby. can create constants inside method?

you cannot that. problem not whether or not constant private. ruby prohibits creation of constant in method definition.

def foo   foo = :foo end # => syntaxerror: ... dynamic constant assignment 

Comments