Reputation: 107
From the Hash below titled 'mambu_repayments' I am trying to iterate over it and only select the repayments that have a state value of anything but GRACE. I run the code and yet everything remains the same all fields are appearing on my view with GRACE and other states
for repayment in mambu_repayments.select {[:state] != 'GRACE'} do
// some code here
end
Any help would be great, my syntax needs tweaking..
Upvotes: 0
Views: 51
Reputation: 357
Ok, I am guessing you are using some kind of collection for payments. This is my answer and you could easily check it from irb.
mambu_repayments = [ { name: 'awesome', state: 'DIFFERENT'}, { name: 'great', state: 'GRACE'} ]
mambu_repayments.select { |payment| payment[:state] != 'GRACE' }.each do |payment|
puts payment
end
Upvotes: 0
Reputation: 1035
'for' are ugly in oriented object language, it do the trick with one more line but consume less memory
mambu_repayments.each do |mambu_repayment|
# Skip GRACE
next if mambu_repayment[:state] == 'GRACE'
# Your view code
end
Upvotes: 1
Reputation: 107
Based off Erez Rabih's answer.. the below worked..
for repayment in mambu_repayments.select {|s| s["state"] != 'GRACE'} do
end
Upvotes: 0
Reputation: 15788
try that:
for repayment in mambu_repayments.select {|o| o[:state] != 'GRACE'} do
// some code here
end
Upvotes: 1