From: Jim Cochrane Date: 2006-11-11T18:05:05+09:00 Subject: Re: can i shorten up this function ? On 2006-11-11, nephish wrote: > hey there, i have a function that checks to see if a string is in a > comma separated list > > it looks like this > def get_in_list(status) > my_list = 'x,j,m,jrn,fnk,foo,other' > my_list_array = my_list.split(',') > if my_list_array.include?(status) > return true > else > return false > end > end > > i dunno, just thought there might be a prettier way to do this. > any suggestions ? > thanks > One possibility: class HardCoded List = 'x,j,m,jrn,fnk,foo,other'.split(',') def self.contains(s) List.include?(s) end end [test:] #!/usr/bin/env ruby $VERBOSE = true require 'hardcoded' puts HardCoded.contains('bother') puts HardCoded.contains('other') --