Doodle, Distilled...

6 views
Skip to first unread message

Jay McGavren

unread,
May 10, 2008, 5:04:05 AM5/10/08
to ruby-doodle
Gonna give a brief presentation on Doodle to the Ruby Users Group on
Monday. While some folks can just wing it, I needed to prepare notes.
The need for brevity and a large font for the projector requires a
short and sweet summary.

In hopes of helping others, here’s what I’ve got…

-Jay McGavren
http://jay.mcgavren.com


#The old, painful way...

class Person
attr_accessor :name, :age, :occupation
def initialize(name, options = {})
options = {
:age => 30
}.merge(options)
@name = name
@age = options[:age]
@occupation = options[:occupation]
end
end

p Person.new('Matz', :occupation => 'Minor Deity')


#The new, improved way:

require 'rubygems'
require 'doodle'

class Animal < Doodle
has :age
end

p Animal.new(:age => 'Sparky')


#Wait, that's not quite right.
class Animal < Doodle
has :age, :kind => Numeric
end
begin
p Animal.new(:age => 'Sparky')
rescue Exception
p $! #Animal.age must be Numeric...
end
#Much better.
p Animal.new(:age => 3)


#Other ways:
p Animal 4
p Animal :age => 5
p Animal {age 6}


#All attributes are required...
begin
p Animal.new
rescue Exception
p $! #missing required attribute 'age'
end
#Unless an initial value is given...
class Animal < Doodle
has :age, :init => 1
end
p Animal.new


#"must" lets you validate with a block.
class Animal < Doodle
has :birthdate, :kind => Date do
must "not be in future" do |value|
value <= Date.today
end
end
end
begin
p Animal.new(
:birthdate => Date.parse('2999-12-31')
)
rescue Exception
p $! #Animal.birthdate must not be in future
end
p Animal.new(:birthdate => Date.parse('1999-12-31'))


#Collectors let you add items to a collection.
class Goose < Doodle
has :name
end
class Flock < Doodle
has :geese, :init => [], :collect => Goose
end
flock = Flock do
goose "Rebeccah"
goose "Jemima"
end
p flock.geese


#There's more:
#http://doodle.rubyforge.org/
#sudo gem install doodle

sean.o...@gmail.com

unread,
May 10, 2008, 1:38:55 PM5/10/08
to ruby-doodle
On May 10, 10:04 am, Jay McGavren <j...@mcgavren.com> wrote:
> Gonna give a brief presentation on Doodle to the Ruby Users Group on
> Monday. While some folks can just wing it, I needed to prepare notes.
> The need for brevity and a large font for the projector requires a
> short and sweet summary.
>
> In hopes of helping others, here’s what I’ve got…
>
> -Jay McGavrenhttp://jay.mcgavren.com
Hi Jay - I'm delighted you want to present on Doodle. I've just
uploaded a copy of the presentation I gave to the London Ruby User
Group last month here:

http://groups.google.com/group/ruby-doodle/web/doodle-presentation.tar.gz

The presentation is called doodle.html and relies on the .css file
and ./ui subdirectory. It's in S5 format and a little temperamental
when resizing on the fly. The tarball contains the input file
doodle.textile and a script textile2s5 which you can use to regenerate
the presentation. The script is a bit rough but might be useful.

One comment on your examples - you're not comparing like with like in
your first non-Doodle example and your second Doodle example. Maybe:

class Person < Doodle
has :name
has :age, :default => 30
has :occupation
end

would be a fairer comparison.

Good luck with your presentation!

Regards,
Sean
Reply all
Reply to author
Forward
0 new messages