Skip to content

Instantly share code, notes, and snippets.

@andycamp
Created August 18, 2012 13:16
Show Gist options
  • Select an option

  • Save andycamp/3386801 to your computer and use it in GitHub Desktop.

Select an option

Save andycamp/3386801 to your computer and use it in GitHub Desktop.
ruby inheritable constants
class A
SUB_TYPES = %w(bass trout salmon)
def valid_sub_type?(sub_type)
self.class::SUB_TYPES.include? sub_type
end
end
class B < A
SUB_TYPES = %w(whale beaver dog)
end
puts A.new.valid_sub_type?('salmon')
puts A.new.valid_sub_type?('tokyo')
puts B.new.valid_sub_type?('beaver')
puts B.new.valid_sub_type?('duck')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment