Thursday, November 26, 2009

Ways to create symbol on the fly

To convet a string to a symbol on the fly:

# Method 1:
1
2
3
type = "elective"
course = "#{type}_course".to_sym
# >> :elective_course

# Method 2:
1
2
3
type = "core"
course = :"#{type}_course"
# >> :core_course

No comments:

Post a Comment

Labels