From: Josh Cheek Date: 2011-10-10T13:52:10+09:00 Subject: Re: Check for boolean status in ruby --bcaec501673feb1e0b04aeea8c56 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Oct 9, 2011 at 11:23 PM, ideal one wrote: > Hi all, > I have to check for a boolean condition, and see whether its > true or false to continue running a method. > Not sure how to implement this in Ruby... > > Dummycode-- > > boolean islogged_in = false; # set default boolean value false > > > for i in 0..2 > > RUN FUNCTION A > > boolean islogged_in = true # Setting boolean to True after successful > FUNCTION A > > RUN FUNCTION B > > end > > > For First Iteration, FUNCTION A should run, but for next Iteration > onwards, only if System is not logged in FUNCTION A should run else > directly FUNCTION B should Run. > How do i set a check in Ruby or should i use some other logic other than > boolean to do this. > > -- > Posted via http://www.ruby-forum.com/. > > This is pretty straightforward procedural code, imo. Perhaps I'm misunderstanding what you're wanting? def function_a puts 'a was run' end def function_b puts 'b was run' end logged_in = false # using 3 because 0..2 iterates over [0, 1, 2] # but we don't actually care about the values 3.times do function_a unless logged_in logged_in = true function_b end # >> a was run # >> b was run # >> b was run # >> b was run --bcaec501673feb1e0b04aeea8c56--