Ruby on Rails creating constant on model
Ruby on Rails (Photo credit: Wikipedia) |
For instance:
1. I have song.rb
class Song < ActiveRecord::Base #-- # constants #++ KEY_SIMBOLS = [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ]
#-- # public class methods #++
def initial_key initial_key_sym = KEY_SIMBOLS end
end2. I have constant KEY_SIMBOLS
3. You can access with:
song = Song.first
song.initial_key
Thanks
Komentar
Posting Komentar
terimakasih komentarnya