Forum: Ruby on Rails Hiding an attribute

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jeffrey L. Taylor (Guest)
on 2006-06-02 01:42
(Received via mailing list)
I am using a smallint database column to store several boolean flags.
The flags are accessible thru facade column accessors.  I'd like to
hide the database column so all access is thru the facade accessors.
How do I do it?

TIA,
  Jeffrey
Andrew R. (Guest)
on 2006-06-11 00:12
(Received via mailing list)
Jeffrey L. Taylor wrote:

> I am using a smallint database column to store several
> boolean flags.  The flags are accessible thru facade column
> accessors.  I'd like to hide the database column so all
> access is thru the facade accessors.  How do I do it?

Module#private.

  class Foo
    def some_column
      puts "a value!"
    end

    def go_here_instead
      some_column
    end

    private :some_column
  end

  Foo.new.some_column        >> NoMethodError
  Foo.new.go_here_instead    >> a value!

http://lnk.nu/ruby-doc.org/9w5.html

-Drew
Bryan D. (Guest)
on 2006-06-11 00:21
Jeffrey L. Taylor wrote:
> I am using a smallint database column to store several boolean flags.
> The flags are accessible thru facade column accessors.  I'd like to
> hide the database column so all access is thru the facade accessors.
> How do I do it?
>
> TIA,
>   Jeffrey

Good solution above. However, why would you want to do such a thing?
Space savings? I think you're spending too much time on some minute
facet of the app instead of actually developing useful code.

Just my 2 cents.
This topic is locked and can not be replied to.