Created
April 4, 2011 16:12
-
-
Save aeden/901888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is madness...or is it genius?! | |
# | |
# Use separate modules for separating private and protected methods from the | |
# public interface. | |
# | |
# Don't forget to run rdoc on this source. | |
class Person | |
module Protected #:nodoc: | |
protected | |
def first | |
@first | |
end | |
def last | |
@last | |
end | |
end | |
end | |
class Person | |
module Private #:nodoc: | |
private | |
def first=(first) | |
@first = first | |
end | |
def last=(last) | |
@last = last | |
end | |
end | |
end | |
# A representation of a person | |
class Person | |
include Person::Private | |
include Person::Protected | |
# Create a new person with a first and last name | |
def initialize(first, last) | |
self.first = first | |
self.last = last | |
end | |
# Get the person's name | |
def name | |
"#{first} #{last}" | |
end | |
end | |
p = Person.new('John', 'Doe') | |
p p.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment