Click 'Connect with Facebook' to join NetworkedBlogs. NetworkedBlogs is a community of bloggers and blog lovers. Join the fun, add your blog, and connect with others who read and write about subjects you like.
| Blog Name: |
Yehuda Katz |
| Url: |
http://yehudakatz.com |
| Language: |
English |
| Topics: |
ruby, rails, jquery |
| Description: |
Yehuda Katz posts on Ruby, Rails, jQuery, and all else tech-related. |
| Popularity: |
5 Followers |
Metaprogramming in Ruby: It’s All About the Self
After writing my last post on Rails plugin idioms, I realized that Ruby metaprogramming, at its core, is actually quite simple.
It comes down to the fact that all Ruby code is executed code–there is no separate compile or runtime phase. In Ruby, every line of code is executed against a particular self. Consider the following five snippets:
class Person
def self.species
"Homo Sapien"
end
end
class Person
class << self
def species
"Homo S
Better Ruby Idioms
Carl and I have been working on the plugins system over the past few days. As part of that process, we read through the Rails Plugin Guide. While reading through the guide, we noticed a number of idioms presented in the guide that are serious overkill for the task at hand.
I don’t blame the author of the guide; the idioms presented are roughly the same that have been used since the early days of Rails. However, looking at them brought back memories of my early days using Rails, when the code made me feel as though Ruby was full of magic incantations and ceremony to accomplish relatively simple things.
Here’
Using the New Gem Bundler Today
As you might have heard, Carl and I released a new project that allows you to bundle your gems (both pure-ruby and native) with your application. Before I get into the process for using the bundler today, I’d like to go into the design goals of the project.
The bundler should allow the specification of all dependencies in a separate place from the application itself. In other words, it should be possible to determine the dependencies for an application without needing to start up the application.
The bundler should have a built-in dependency resolving mechanism, so it can determine the required gems for an entire set of dependencies.
Once the dependen
Inherited Templates With Rails
A nice feature of some template languages (for instance, Django’s) is the ability to create templates that can be “inherited” by other templates. In effect, the goal is to create a template that has some missing content, and let “inheritors” fill in that content downstream.
It’s not terribly difficult to add this feature to Rails; let’s first design the API. First, the parent template (_parent.html.erb):
Before in parent
<%= first_from_child %>
<%= second_from_child %>
After in parent
We just use normal partial locals for the parent API, because they’re a well-underst
Emulating Smalltalk’s Conditionals in Ruby
If you follow my blog, you know that I enjoy emulating language features from other languages (like Python) in pure-Ruby. On the flight back from London, I read through Smalltalk Best Practice Patterns, and was reminded that Smalltalk doesn’t have built-in conditionals.
Instead, they use method calls (aka message sends) to do the heavy lifting:
anObject isNil
ifTrue: [ Transcript show: 'true'. ]
ifFalse: [ Transcript show: 'false'. ].
In contrast, the typical way to do that in Ruby is:
Not enough data.
Calculated for blogs with 20+ followers.
- ConceptSpace
rails, css, javascript
- GAPDesigns
Web Development, Ruby, Javascript
- VCS
Food, ColdFusion, jQuery
- I Love Colors
graphic design, wordpress, jquery
- My Idea My Life
PHP, Web, Jquery
Questions? contact: networkedblogs@ninua.com
Copyright (C) 2008, Ninua, Inc.