kinda new to Rails.
How would you simplify, beautify this method:
def find_index
index = 0
@ipn.each {|p|
index = 4 if p = "new" #this is just a dummy line
}
index
end
As you can see, it’s ugly. How can I remove the index definition at the top and the index at the bottom to return – The Ruby way?
I think you want this method:
http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-find_index
I also change the variable name ‘@ipn’ to ‘@ipns’, since it seems to be an enumerable.
And to avoid confusion, I might rename the method to ‘find_ipn_index’, so it looks like this:
Or, if self.ipns is available, don’t define a new method at all for this, just call: