Ruby separating an array of strings by checking whether or not the object inherits from a certain class -


  • I have a string in which I read a file from x
  • I have an empty array y
  • some string objects are integer
  • how can I separate the integers with strings, special forms I'm still trying to call to_a

with

  x.each do | S | If s.to_i.is_a? (Integer) y & lt; & Lt;  

But it just changes everything in an integer and puts it in y , there is a way to see that an object is actually in the integer class ?

Add sample input / output

  x = ["this", "is", "one", "random" "", "Key", "ka", "number", "111113087403957304739703975", "how", "can", "me", "read", "combination", "ka", "text", " And "," a "", "in this."] Y = [111113087403957304739703975]  

< Pre> x.each do | s begin the integer Logic Argument arguments yy

If a string is applied that does not parse as integer , Then integer () a argumentErro R . You can use it to find the integer string.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Algorithm negotiation fail SSH in Jenkins -

java - Messages from .properties file do not display UTF-8 characters -