Skip to content

Instantly share code, notes, and snippets.

@aeden
Created April 4, 2011 16:12
Show Gist options
  • Save aeden/901888 to your computer and use it in GitHub Desktop.
Save aeden/901888 to your computer and use it in GitHub Desktop.
# 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