Here is a PHP Snippet I wrote. It’s a cool trick to for calling multiple methods in a much simpler way. Inspired by Ruby’s ActiveRecord.
<?phpinterfaceMember{functionlogin($username,$password);functionupdate($status);}class BaseimplementsMember{publicfunctionlogin($username,$password){echo"You will be logged in as: {$username} with Password: {$password}\n";}publicfunctionupdate($status){echo"Your New Status Message is: {$status}\n";}publicfunction__call($method,array$argv){if(preg_match('/^do_*/i',$method)){foreach(explode("_and_",substr($method,3))as$k=>$v){$param=array();foreach($argv[$k]as$value){$param[]="'{$value}'";}$param=join(", ",$param);$code='$this->'.$v."({$param});";eval($code);}}}}class UserextendsBase{publicfunctionsay_hello($message){echo"Message: {$message} \n";}}$usr=&newUser();$usr->do_login_and_update(array("username","password"),array("Hello World"));# Prints the following:# You will be logged in as: username with Password: password# Your New Status Message is: Hello World#$usr->do_login_and_say_hello(array("username","password"),array("Hi how are you?"));# Prints the following:# You will be logged in as: username with Password: password# Message: Hi how are you?#$usr->do_login_and_update_and_say_hello(array("username","password"),array("Hello World"),array("Hi how are you?"));# Prints the following:# You will be logged in as: username with Password: password# Your New Status Message is: Hello World# Message: Hi how are you?#?>
Meta Programming is code that writes code. See the code sample below.
I have made a screencast of this process. View it here
#!/usr/bin/env rubyclass Productdef initialize(items)items.each{|item|Product.product(item)}enddef self.product(item)code=%Q{
def add_#{item}(item)
@#{item} = [] unless @#{item}
@#{item} << item
end
def display_#{item}s
@#{item}.each {|item| puts item }end}class_eval(code)endendclass Item<Productdef initialize(*items)super(items)endendcart=Item.new(:book,:computer,:music)cart.add_book(:Ruby)# => Add a book to our cart itemscart.display_books# => We want to display All books we have addedputs"\n"cart.add_computer(:Apple)cart.add_computer(:Dell)cart.add_computer(:Sony)cart.display_computers# => Display All Computersputs"\n"cart.add_music(’Modest Mouse‘)cart.add_music(’Northstar‘)cart.display_musics# => Display All Music Items
It is official LastBridge.net is out for public consumption! Again for those who are lost and don’t know what this “LastBridge” is it’s for listening to your last.fm radio stream on the Roku SoundBridge.I have made a screencast on How To use LastBridge. If anyone still needs help or just want to leave your opinions on this project, leave a comment or two. Thanks.Enjoy!
What? What is this? Well, yeah… it is another project of mine. I call it LastBridge, like the name? its original… anyways.. So LastBridge is a web app for users of the Roku SoundBridge like myself. Basically you can listen to your last.fm music on the SoundBridge without having to install anything or hosting any files. I previously wrote the same thing in a much cheaper less good looking way, in PHP. This time I have rewritten it using Ruby On Rails. As soon as I release it make sure to check it out.
Wow, you don’t see rants like this every day. Zed Shaw, who created Mongrel, a library and web server that just about everyone uses to serve rails applications, is basically a God in the Rails community. In a post today called “Rails Is A Ghetto” he tears into a number of leading Rails developers, the community in general, and a number of startups (and Google).via Techcrunch
Hello everyone it is I… Thanks to everyone who as emailed me, said good stuff about my work, and gave me tips and everyone who as made a comment. Thanks everyone!-fernyb
Blaine sets his sights on the same two effeminate idiots from the last two videos. And unfortunately for them, the third time’s the charm.read more | digg story
If you’re just getting into Rails or you’re not entirely clear on the whole REST thing, as I was, take a look at Gregg’s video presentation over at railsenvy.com It’s good.