Wednesday, July 30, 2008

DHH at "Startup School"

<div><a href=''>Share and annotate your videos</a> with Omnisio!</div>

Tuesday, July 29, 2008

Knol and Semantic Web

...reading between the lines on this for awhile... Google is seemingly going to move in the semantic direction... this is a step... by referencing a Knol (or a Wiki link or any link to a definition) in an RDF, you define that element in the HTML hierarchy with a real meaning "a shark is an aquatic creature, yada yada". Search for "shark" not only pulls up hyperlinked web content (current legacy which uses headers, urls, hyperlinks... to relate search terms to highest relevance), but pulls up all in the 'web' defined, so it pulls up shark, the creature that swims, not Shark the former wide receiver for the Irish Jeff Samardijza, nor The Shark Greg Norman, for instance... it's a way to relate words with different definitions in a semantic way, which is a common and big problem to solve on the web. It also enables new automated ways for apps to talk with other apps. The web has been missing this step towards progressing.

Google doesn't want to be beholden to Wikipedia... and why should they be, they have the resources and the intelligence to pull this off and move it forward.

... those ahead of the curve, start thinking about and programming your internetz and interwebs semantically...

Thursday, July 24, 2008

Metaclasses and Ruby Inheritance Chain

This is a very large and involved topic. (great topic! it is part of what makes Ruby so powerful)
You can add new methods to a Class on the fly at anytime. Can also overwrite methods at any time. And, in Ruby, this truly means virtually any Class. Including classes like Array, String, etc.

Let's say we have

> class Course
> attr_accessor :id, :name
> def initialize( id, name)
> @id, @name= id, name

> end
> end

> c = 1, "Augusta National" )
=> #<
Course:0x81cfb94 @id=1, @name="Augusta National"...

> c.class
=> Course

=> 1
=> "Augusta National"

So in this case, a Course object, once initialized, will have a
@id and a @course variable. It can hold
any other variables at any time too...

> c.instance_variable_set( "@par", 72 )
=> 72
> c.par
=> MoMethodError: undefined method 'par' for #<Course..

It's holding that variable for par, but now we cannot get at it without a read method. So let's say you
wanted to only have the reader/writer methods for par on that instance,
not on the class
(just an example).

Classes hold methods, objects do not. Except in the case of metaclasses:
> class << c
> attr_accessor :par
> def pretty_par
> puts "par: #{@par}"
> end
> end

Now you can do
> c.par
=> 72
Also when you do:
> c.methods
=> ["par", "id", "name", "pretty_par", ...] #=> these are referred to as the
#=> object's "Singleton methods"

but when you show the methods for the Course class:
> Course.methods
=> ["id", "name", ...] # i.e. no par, or pretty_par, because there is no method
# for these in the Course class, only the c metaclass

> c2 =, "Shinnecock Hills")
#<Course:0x91cfb94 @id=2, @name="Shinnecock Hills"

but it won't have access to any of the Singleton methods in c (i.e. neither "c2.par", nor "c2.pretty_par" method
calls will work. They only work in the c metaclass).

You see, because when Ruby looks for a method, it first looks at the metaclass.
i.e. the metaclass intercepts the request, and checks for methods there first.

Then it goes to the object's class, then the SuperClass of that object, then any super's of that object and so on
...all the way back to the Object base class.

You can insert methods into the class, or into an object's metaclass at any level in the inheritance chain.
Very powerful.

One more beauty... if you attach a:
def method_missing
puts "there was no method that matched that"
you can intercept the call to a missing method (anywhere in the inheritance chain, the class, the metaclass, etc)
and do things like creating methods on the fly, programmatically.

It's called "monkey patching" (some people call it "Duck punching", and there are other names).
Ruby is a great language to metaprogram with. Rails uses method_missing often (along with const_missing) --
for instance, ActiveRecord uses method_missing to dynamically support the find_ methods.

That's a whole other interesting topic in itself to explore!