[rspec-users] Style issue

Zach Dennis zach.dennis at gmail.com
Thu Apr 23 20:13:15 EDT 2009


On Thu, Apr 23, 2009 at 8:11 PM, Zach Dennis <zach.dennis at gmail.com> wrote:
> On Thu, Apr 23, 2009 at 3:59 PM, Mark Wilden <mark at mwilden.com> wrote:
>>  On Thu, Apr 23, 2009 at 12:05 PM, James Byrne <lists at ruby-forum.com> wrote:
>>
>>> When /currency exchange rate transfer file should contain rates/ do
>>> found = false
>>> fx_code = 'USD'
>>> File.open(FOREX_XFR_FN).each do |line|
>>>   found = true if
>>> /.*fx_target#{fx_code}.*fx_rate(\d+\.\d{4}).*/.match(line)
>>>   break if found
>>> end
>>> fail(ArgumentError, "Exchange Rate not found for #{fx_code}") if not
>>> found
>>> end
>>
>> I find this more straighforward and easy to understand:
>>
>>  When /currency exchange rate transfer file should contain rates/ do
>>   fx_code = 'USD'
>>   File.open(FOREX_XFR_FN).each do |line|
>>     return true if
>> /.*fx_target#{fx_code}.*fx_rate(\d+\.\d{4}).*/.match(line)
>>   end
>>   fail(ArgumentError, "Exchange Rate not found for #{fx_code}")
>>  end
>
> I'd even vote for the more concise form:
>
> When /currency exchange rate transfer file should contain rates/ do
>  fx_code = 'USD'
>  IO.readlines(FOREX_XFR_FN).any?{ |line|
>    line.match /.*fx_target#{fx_code}.*fx_rate(\d+\.\d{4}).*/
>  } || fail ArgumentError, "Exchange Rate not found for #{fx_code}" unless found
> end

Whoops, make that...

When /currency exchange rate transfer file should contain rates/ do
 fx_code = 'USD'
 IO.readlines(FOREX_XFR_FN).any?{ |line|
   line.match /.*fx_target#{fx_code}.*fx_rate(\d+\.\d{4}).*/
 } || fail(ArgumentError, "Exchange Rate not found for #{fx_code}")
end

>
>
>>
>> ///ark
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>
>
>
> --
> Zach Dennis
> http://www.continuousthinking.com (personal)
> http://www.mutuallyhuman.com (hire me)
> @zachdennis (twitter)
>



-- 
Zach Dennis
http://www.continuousthinking.com (personal)
http://www.mutuallyhuman.com (hire me)
@zachdennis (twitter)


More information about the rspec-users mailing list