06 September 2010

The Ruby Reflector

Topic

Person

  Source Favicon
By anup.narkhede of for i in infinity 1 day ago.
Email

To create new instances of Person class: foo = new Person({ id: 1, name: 'foo' }) bar = new Person({ id: 2, name: 'bar' })

Attribute values can be accessed using getter and setter functions: foo.get('name') foo.set('name', 'railsbob')

The Base class provides a collection array to store instances and they can be added as: Person.add(foo) Person.add(bar)

The collection belongs to the page context when used in a browser. Records …

anup.info Read
  Source Favicon
By David of Riding Rails - home 8 days ago.
Email

def new_project(digest, project, person) @ digest, @ project, @ person = digest, project, person

attachments['digest.pdf'] = digest.to_pdf attachments['logo.jpg'] = File.read(project.logo_path)

mail( :subject => "Your digest for #{ project.name}", :to => person.email_address_with_name ) do |format| format.text { render :text => "Something texty" } format.html { render :text => "Something <i>texty</i>" …

weblog.rubyonrails.org Read
  Source Favicon
By Iain Hecker of Adventures with Ruby 1 month ago.
Email

…these structs you can output their gender or name in views without doing anything special: % dl [ @ person ] % dt = Person .human_attribute_name( :name ) % dd = @ person .name % dt = Person .human_attribute_name( :gender ) % dd = @ person .gender

In this example, Person is actually an aggregate of the entity Person and two value objects, called Name and Gender . Although all attributes are flattened out in your persistence layer (in this case, your database table); they …

iain.nl Read
  Source Favicon
On Ruby Quicktips 4 months ago.
Email

You can use attribute names followed by question mark. Let's assume there is an ActiveRecord class Person , having first_name and last_name as attributes. p = Person.new p.first_name = 'Mike'

p.first_name? # => true p.last_name? # => false

Tip reblogged from milandobrota .

rubyquicktips.tumblr.com Read
  Source Favicon
By Radar of The Life Of A Radar 5 months ago.
Email

We have two models who's names aren't important so excuse me if I use the name Person and Address to represent them. They are nothing of the sort. In their purest form to replicate this issue, they are defined like this: class Address < ActiveRecord::Base has_and_belongs_to_many :people end

class Person < ActiveRecord::Base has_and_belongs_to_many :addresses accepts_nested_attributes_for :addresses

end

When we go to create a new Person record: Person.create(:addresses_attributes …

frozenplague.net Read
  Source Favicon
By susie jones81 of Forum Discussions - Enterprise Rails 5 months ago.
Email

Hi im A simple Person Who Loves To Watch Movies, TO gain Friends and also i love to watch movies, Cook, Eat, Shopping, And Also i love to Write An essay

enterpriserails.chak.org Read
  Source Favicon
Email

<% show_for @ person do | p | %> <% = p . attribute :first_name %> <% = p . attribute :last_name %> <% = p . attribute :confirmed ? %> <% = p . attribute :created_at , :format => :short %> <% = p . attribute :age , :if_blank => "No age" %> <% p . attribute :photo do %> <% = image_tag ( @ person. photo_url ) %> <% end %> <% end %>

Here is an example output you will get:

<div class="show_for person" …

blog.plataformatec.com.br Read
  Source Favicon
By David of Signal vs. Noise 7 months ago.
Email

…with a stick when things are going great. And getting an intro to Mr. Very Important Person before you have anything of material value is usually not going to give you much anyway.

5. Taking money means big exit or IPO

I'd argue the opposite. When you take money, your exit is bound to be smaller unless you're playing the Web 2.0 lottery game (where a few lucky contestants gets bought for sums completely uncorrelated to business fundamentals). Taking money means giving up equity, …

37signals.com Read
  Source Favicon
By wycats of Katz Got Your Tongue? 7 months ago.
Email

…involving modularity. In essence, Rob wants to be able to "decorate" the Person class to include teacher traits.

Nick's response would have been to create a factory that creates a Person proxy decorated with Teacher properties. And he would have been technically correct, but that description obscures the Ruby implementation, and makes it sound like we need new "Factory" and "Decorator" objects, as we do, in fact, need when programming in Java

yehudakatz.com Read
  Source Favicon
By wycats of Katz Got Your Tongue? 8 months ago.
Email

Here's the Person model with validations and serialization:

class Person include ActiveModel::Validations include ActiveModel::Serialization validates_presence_of :first_name , :last_name attr_accessor :attributes def initialize ( attributes = { } ) @ attributes = attributes end def read_attribute_for_validation ( key ) @ attributes [ key ] end end

Others

Those are just two of the modules available in ActiveModel. Some others include:

AttributeMethods : Makes it easy …

yehudakatz.com Read