How can I check whether a parameter isa Symbol?
The question is in the title.
My parameter can be either a string or a symbol and depending upon which it is I want to pe开发者_开发知识库rform different actions. Is there a way to check for this in Ruby?
def foo(arg)
  if arg.is_a?(Symbol)
    do_symbol_stuff
  else
    do_string_stuff
  end
end
Another solution
def foo(arg)
  case arg
    when Symbol
      do symbol stuff
    when String
      do string stuff
    else
      do error stuff
  end
end
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论