定数の扱い方について
- クラスに定義する
- アクセスするためのメソッドを定義する
- 定数へのアクセスは、 (2) のメソッドのみ使用する
Add this line to your application's Gemfile:
gem 'ans-constant_definer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ans-constant_definer
class MyClass
include Ans::ConstantDefiner
const_def :my_const, %w(a b c)
end
MyClass.my_const # ["a","b","c"]
MyClass.new.my_const # ["a","b","c"]
- Ans::ConstantDefiner を include すると
const_defクラスメソッドを定義 const_defは第一引数のupcaseを名前、第二引数を値とする定数を定義const_defは第一引数の名前でクラスメソッド、インスタンスメソッドを定義して、それぞれ第二引数を返す
class MyClass
include Ans::ConstantDefiner
const_def :my_const, %w(a b c),
class_method_prefix: "class_prefix",
instance_method_prefix: "instance_prefix"
end
MyClass.class_prefix_my_const
MyClass.new.instance_prefix_my_const
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request