Question about Inheritance

I have two simple classes. One inherits from the other and calls "super()" in its initialize method. But the super does not seem to do what I expect it to do. I expect the super() to initialize two variables, but when I call the method to display the initialized errors, I do not get the value (it things @errmsg is nil). Here they are:

class DBBase
  def initalize
    @failed = false
    @errmsg = 'n/a'
  end

  def clear
    @failed = false
    @errmsg = 'n/a'
  end

  def failure
    @failed
  end

  def success
    @failed != true
  end

  def error
    "Error: #{@errmsg}"
  end

  def connect
    SQLite::Database.new(DBNAME)
  end

  attr_accessor :failed, :errmsg
end

(and here is the shortened version of the inheriting class)...

## This class models the People table. It allows the creation,
## loading, modification and saving of a single person.

class Person < DBBase
  def initialize(id=nil, lname=nil, fname=nil, mname=nil, nname=nil, sex=nil, dob=nil)
    super()
    @id = id
    @lname = lname
    @fname = fname
    @mname = mname
    @nname = nname
    @sex = sex
    @dob = dob

    if @id != nil
      @added = false
    else
      @added = true
    end

    @modified = false
    @loaded = false
  end

···

--------------------------

Michael Jessop wrote:

I have two simple classes. One inherits from the other and calls "super()" in its initialize method. But the super does not seem to do what I expect it to do. I expect the super() to initialize two variables, but when I call the method to display the initialized errors, I do not get the value (it things @errmsg is nil). Here they are:

class DBBase
def initalize
   @failed = false
   @errmsg = 'n/a'
end

The initialize method in class DBBase is spelled incorrectly.

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

Oh for the love of friggin' PETE! I spent an hour on this!!!!!!!!!!

I wish you were here so you could smack me with bat.

Thanks!

Mike

···

On 2005-08-30 13:28:46 -0700, Jamey Cribbs <cribbsj@oakwood.org> said:

Michael Jessop wrote:

I have two simple classes. One inherits from the other and calls "super()" in its initialize method. But the super does not seem to do what I expect it to do. I expect the super() to initialize two variables, but when I call the method to display the initialized errors, I do not get the value (it things @errmsg is nil). Here they are:

class DBBase
def initalize
   @failed = false
   @errmsg = 'n/a'
end

The initialize method in class DBBase is spelled incorrectly.

Jamey

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.

Just for fun...

$ ruby code-nanny.rb
Did you type too fast again? 'initalize' != 'initialize'
Did you type too fast again? 'intialize' != 'initialize'
Did you type too fast again? 'inaltiaez' != 'initialize'
Did you type too fast again? 'initiliaze' != 'initialize'
$ cat code-nanny.rb
module CodeNanny
  def method_added(m)
    if /^in[ital]{2,6}[alize]{2,6}\b/ =~ m.to_s
      if m != :initialize
        warn "Did you type too fast again? '#{m}' != 'initialize'"
      end
    end
  end
end

class Foo
  extend CodeNanny
  def initialize
  end

  def initalize
  end

  def intialize
  end

  def inaltiaez
  end

  def initiliaze
  end
end

Foo.new

Michael Jessop wrote:

···

Oh for the love of friggin' PETE! I spent an hour on this!!!!!!!!!!

I wish you were here so you could smack me with bat.

Thanks!

Mike

On 2005-08-30 13:28:46 -0700, Jamey Cribbs <cribbsj@oakwood.org> said:

Michael Jessop wrote:

I have two simple classes. One inherits from the other and calls
"super()" in its initialize method. But the super does not seem to
do what I expect it to do. I expect the super() to initialize two
variables, but when I call the method to display the initialized
errors, I do not get the value (it things @errmsg is nil). Here they
are:

class DBBase
def initalize
   @failed = false
   @errmsg = 'n/a'
end

The initialize method in class DBBase is spelled incorrectly.

Jamey

Confidentiality Notice: This email message, including any attachments,
is for the sole use of the intended recipient(s) and may contain
confidential and/or privileged information. If you are not the
intended recipient(s), you are hereby notified that any dissemination,
unauthorized review, use, disclosure or distribution of this email and
any materials contained in any attachments is prohibited. If you
receive this message in error, or are not the intended recipient(s),
please immediately notify the sender by email and destroy all copies
of the original message, including attachments.

--
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

You missed 'initialise'! (I remember various ruby-lint projects being
mentioned in the past - anyone know what happened to them?)

martin

···

Joel VanderWerf <vjoel@path.berkeley.edu> wrote:

Just for fun...

$ ruby code-nanny.rb
Did you type too fast again? 'initalize' != 'initialize'
Did you type too fast again? 'intialize' != 'initialize'
Did you type too fast again? 'inaltiaez' != 'initialize'
Did you type too fast again? 'initiliaze' != 'initialize'
$ cat code-nanny.rb
module CodeNanny
  def method_added(m)
    if /^in[ital]{2,6}[alize]{2,6}\b/ =~ m.to_s
      if m != :initialize
        warn "Did you type too fast again? '#{m}' != 'initialize'"
      end
    end
  end
end

Martin DeMello wrote:

···

Joel VanderWerf <vjoel@path.berkeley.edu> wrote:

Just for fun...

$ ruby code-nanny.rb
Did you type too fast again? 'initalize' != 'initialize'
Did you type too fast again? 'intialize' != 'initialize'
Did you type too fast again? 'inaltiaez' != 'initialize'
Did you type too fast again? 'initiliaze' != 'initialize'
$ cat code-nanny.rb
module CodeNanny
def method_added(m)
   if /^in[ital]{2,6}[alize]{2,6}\b/ =~ m.to_s
     if m != :initialize
       warn "Did you type too fast again? '#{m}' != 'initialize'"
     end
   end
end
end

You missed 'initialise'! (I remember various ruby-lint projects being
mentioned in the past - anyone know what happened to them?)

martin

:slight_smile: I almost added that, but I coudn't think of a humorous way to accuse
the programmer of being a Queen's English speaker (maybe that's humorous
enough as it is).

--
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

If any one really wants to use this, then to make sure there are no
false positives, we should permit #initial. According to one local
dictionary on my system, initial and initialize are the only matches for
the regex.

module CodeNanny
  def method_added(m)
    if /^in[ital]{2,6}[alize]{2,6}\b/ =~ m.to_s
      if m != :initialize and m != :initial
        warn "Did you type too fast again? '#{m}' != 'initialize'"
      end
    end
  end
end

···

--
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407