Re: ruby and true



On Apr 30, 9:29 am, Robert Klemme <shortcut...@xxxxxxxxxxxxxx> wrote:
On 30.04.2007 16:42, aidy.le...@xxxxxxxxxxxxxx wrote:



Hi,

I have some code the checks whether some text is on the HTML page

@@log.test_results(ie.contains_text('Dashboard')

I should get a TRUE (it's there), but it is returning the figure 62.
Is anything > 0 in Ruby true? If so, why, and shouldn't the object
automatically change to boolean?

My xml then is falling through

if result == TRUE then
test_status = @test.add_element 'teststatus'
test_status.text = 'PASS'

There's only two falses in Ruby: false and nil. Everything else is
considered true.

Please note also, that it is usually a very bad idea to try to compare a
boolean value with a boolean constant in a boolean context. Just use
the value or use "!" or "not" to negate. This applies to all sorts of
programming languages (just think of doing "if ( x == TRUE )" in C...

Kind regards

robert

as Robert has said, its generally bad to say if x==true

in this case contains_text does a reg exp on the html of the page, so
it returns either the start position of the string ( as an integer) or
nil

.



Relevant Pages

  • Re: methods and default values
    ... I'd represent false by nil or false and not "no". ... directly use the boolean value. ... def Text2 ...
    (comp.lang.ruby)
  • ICDecompress problem
    ... TDIB = record ... AVIBufferOut: Pointer; ... function InitAVI: Boolean; ... if ADIB.Bits nil then ...
    (microsoft.public.win32.programmer.mmedia)
  • Re: SBM2 programming error
    ... Microsoft defines NULL as zero. ... Checking a pointer for "NIL" is simply a boolean test of that value. ... This would let you define types as boolean types and not ...
    (comp.lang.modula2)
  • Re: Overloaded logic operators
    ... x and x.foo# if x is not nil, ... In languages such as Ruby, Lua, Io, Python and JavaScript, does the ... Let the default boolean type be a type with more than two values, ... includes sequential logical operators that are not bitwise). ...
    (comp.compilers)
  • Re: Why not a setf-able NIL ?
    ... i'd say using 0 and 1 as boolean values *is* a workaround. ... setfable NIL simply does not make sense, ... here i meant binding in general rather than imperatively setting value. ... binding NIL does not have sense. ...
    (comp.lang.lisp)