0

Here is my loop

 subscriptions.each do |s|
     if s.is_active? && s.is_current?
        #do some stuff
     end
  end

subscriptions is an array that has one element. However it does not hit the if statement inside the loop.

When I step through it using rdebug I get this

(rdb:1748) p subscriptions.count
1

I am on ruby version 1.8.7

Am I missing something?

Thank you in advance for your help.

6
  • What about subscriptions.length? How are you sure that it's never stepping into the block? Commented Jan 2, 2013 at 17:51
  • Put here the content of subscriptions by printing the "puts subscriptions.inspect". Commented Jan 2, 2013 at 17:56
  • 1
    puts subscriptions.select{ |s| s.is_active? && s.is_current? }.length Commented Jan 2, 2013 at 17:58
  • @ChrisHeald subscriptions.length returns 1 also. I know that it is not going into the block because I am using ruby-debug to step through the code. I see it skip the block and go on to some code that is past this loop. Commented Jan 2, 2013 at 19:36
  • 1
    @kjennings.dev You're correct. It basically filters the array to only the elements that met your conditions. Commented Jan 2, 2013 at 19:42

2 Answers 2

1

Check if it works?

subscriptions.each { |s| puts s }

If above code prints your elements, then there is some issue with your condition i.e. below code is not proper:

if s.is_active? && s.is_current?
  #do some stuff
end
Sign up to request clarification or add additional context in comments.

Comments

0

The problem ended up being Case sensitivity on some data in the DB. All is good now. It is peculiar that it seemed to have skipped the block, but I am sure it is my own ignorance of how ruby-debug works. I am after all relatively new to ruby/rails development. Thanks all!

2 Comments

Did you use next rather than step? next will not descend into functions, whereas step will. A block is basically an anonymous function.
I was using next. Amazing help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.