Observer and Ducks
If you have implemented Observer pattern in any statically typed language, you know that you need an explicit Observer class/interface for the pattern, which will be extended by the actual concrete classes and some ‘update’ kind of method should be overridden in order to propagate the observations.Basically taking advantage of inheritance.
Here comes a duck type language like Ruby, as there are no types to be declared you can pass in any object to the observable and let it call the update method, you don’t need any parent Observer class. If the method is available in the object it will be called and the observation will be accomplished.
Now we can extend this more, The observable object will call any method it wants and ruby’s method_missing will take care of the methods that the individual observers don’t want to define. Cool eh? Check out this simple example:
So I quote this again “If it walks like a duck and quacks like a duck, it must be a duck.”
Game of life in Ruby
Here is the code, I think this needs to be written in more stylish way. If you have any suggestions please comment.
Your new Remote Control : NaradMuni
Hello all,
Its been a hectic month for me, many things happened, good and bad(especially about home loan, I am going to write a blog post about that in Vartool.). One of the good things that happened is that I met few Ruby enthusiasts and I have decided to write some cool Ruby program again! So without wasting anymore time, lets go…
Scenario : I am working on my computer(A) and my teammate is working on a shared computer(B), Now i have some urgent work on computer B, lets say i have to read some code i have written yesterday. Now I can’t go to the machine and copy that code(because the machine is remotely located .. geographically) and i can’t remotely access it through remote desktop because i don’t want to disturb him. What should I do?
Well don’t worry, NaradMuni is here.
What is NaradMuni : NaradMuni is very small (tiny) ruby application which will let you run a terminal command on another machine from your machine.
How : Using DRb. Well, I have written a DRb server and client, you run the server on the shared machine(Computer B from the scenario) and client on your machine. The client will accept the commands you want to run on the server and send it to the server using DRb. Server then runs the command using IO.popen and return the result to the client. Simple!
Here is an output, Server is running on my machine(pdandwate) and client on another(kalea, thanks to Kale for letting me use his machine ;) ) :
Start to End : Twitter client in Shoes
Prerequisites :
- I hope you have Shoes installed on your machine, operating system does not matter :)
- oauth gem (gem install oauth will do the trick or sudo if you have to!)
- json gem as well(to parse the response) (gem install json)
Let’s start :
Step 1 : Register your application at Twitter (HERE), give some cool name like “Rubydubee”(not this x-( ).
Step 2 : Lets first write our own library(ehh? don’t worry you can just copy the code here :) ), But you can try to understand that… very small & simple if you know the OAuth protocol.(the oauth gem does all the magic.)
Step 3 : Let’s write our Application
The code is intuitive! isn’t it? if you need any help plz comment!
After you run this “shoes main.rb” it will look somewhat like this :
Thanks for reading this post!
Next post will bring following points :
- Error handling
- Sophisticated architectural design and UI
- More features
Keep reading!!! :)
Ruby GUI - Web to Desktop
Hello! to all those good looking(:p) unhealthy smart creatures out there, A very very good morning(its 2:35 AM here :D ).
You might have made some guesses about this post from the title, and if you are excited to read the whole post then let me tell you that you are the right kind of person to do this. Please go on —-
There are thousands of web developer who are master at designing a web gui. but when it comes to designing the similar kind of gui for desktop application, it becomes very very tough for them to get the same look and feel.Hence for those i propose a very very simple way to port the web gui to desktop application.
I have started a project (webtodesktop) which will convert an HTML file into a desktop application along with the same styling.
See the demo … Check README.
Will soon be writing more HowTos on that…Cya!!!
Minesweeper board generator.
Have you ever played Minesweeper? This cute little game comes with a certain operating system whose name we can’t remember. The goal of the game is to find where all the mines are located within a M × N field.
The game shows a number in a square which tells you how many mines there are adjacent to that square. Each square has at most eight adjacent squares. The 4 × 4 field on the left contains two mines, each represented by a “*” character. If we represent the same field by the hint numbers described above, we end up with the field on the right:
* . . . * 1 0 0
. . . . 2 2 1 0
. * . . 1 * 1 0
. . . . 1 1 1 0
Solved this Problem check it out here.All you have to do is checkout the Minesweeper folder and ruby the main.rb file.
See ya!!

