Reputation: 2846
I have a Rails4 application to which I want to add a model named 'Parameters' It's a good choice in terms of the models purpose, but I worry that it is also a common programming term.
What is the best practice (individual steps) to ensure that:
Parameters
parameter.thing
... will not conflict with a reserved word in Ruby, Rails, or my particular Gem list?
Upvotes: 1
Views: 208
Reputation: 121010
Ruby has a concept of open classes. That said, when the class MyClass
is defined somewhere, it’s perfectly valid to have the following in your code:
class MyClass
def another_method
# do something useful
end
end
That said, there is no “reflection-like” mechanism for this action, since it is how Ruby is intended to work.
One might build the complicated logic like this:
Parameters
class loaded;$defined = const_get('Parameters') || true rescue false
;$defined
global (it’s made global here for the sake of an example) to determine whether the name is free.or:
TracePoint#new(:class)
on Parameters
to detect whether only yours was loaded.or
ObjectSpace#each
to detect other classes.or even
But I would not go with any of solutions above. Just call your class MyAppParameters
and live with this name.
Upvotes: 1
Reputation: 10696
An IDE like RubyMine should warn you by coloring the text whenever you use a reserved word, but for people like me who use glorified text editors, you can always check this list of Rails related reserved words when you're not sure.
Upvotes: 1