RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  

skorks — 34 posts

Have you ever wondered if your Rails app is robust enough and how you can make it more so? Tuts+ has a comprehensive overview of some of the things you can do at the code level, to make your application more fault tolerant. Check it out.
The New Relic agent gem is very interesting to look at to figure out how it hooks in to so many frameworks automatically. In addition it also exposes the same kind of tools to your code. Learn about this as well as New Relic custom metrics in the latest post on Tuts+.
Recently I was asked a question about ‘& parameters’ when you define and/or call methods which take a block. When do you put an ampersand in front of block variables and when do you not? It is often hard to remember how confusing Ruby can be when you’re starting out. So, let’s dig into this a little more deeply and shed some light on what’s going on.
Ruby doesn't support nested exceptions, but the ability to rescue an exception, raise your own, but still retain the original one, can often be very handy.
We work with JSON APIs every day, so it helps to know what options there are when it comes to formatting our JSON on the command line. Your easiest/best bets are the Python JSON tool (if there is no other option), YAJL tools, or the ppjson gem, written using the escort framework.
When using instance_eval in Ruby, the block will behave in a distinctly unclosure-like manner, here we dig deeper to see what happens and try to roll our own instance_eval that allows us to retain the closure semantics we have come to expect from Ruby blocks.
For a Rails developer, getting HTTPS going locally isn't just a matter of adding a gem to your Gemfile, and running bundler - unfortunately it's a bit more involved. In this post, I’ll go through some of the steps that I took to get HTTPS going on a Rails application running locally under POW. Hopefully, it’ll be of use to somebody.
When you're using Rails, swapping a new web server in is pretty painless. But if you want the "rails server" command to pick up your new web server as a default - it will require a little bit of hacking. This shows you how and does a bit of a dive into Rails and Rack in the process.
There aren't enough implementations of interesting algorithms in ruby. The subset sum problem has a couple of interesting algorithmic solutions, it also happens to be the object of a programming challenge I came across recently. So, here are two solution to this problem that I came up with (a naive exponential time one as well as a better dynamic programming one) both implemented in ruby.
Have you ever wondered what it would take to write a unit testing framework in Ruby, I did, which in turn led me to wonder what the smallest possible viable framework would be. Turns out, it's even smaller than I thought.
I often find it valuable to go back to the fundamentals of whatever skill I am trying to master periodically, as I gain more experience. To that end I recently decided to revisit Ruby procs and lambdas and the differences between them, hope you find it interesting.
There are a great many decent developers out there who don't know what a closure is, but functional languages have been making a comeback recently so it really behooves you to know about functional concepts. Here is a simple explanation of closures using Ruby to demonstrate.
The other day something curious happened that made me question how I use bang methods (and their non-bang cousins). You see, I wanted to merge some hashes and the performance difference between the bang and non-bang version of merge was astounding, so I decided to dig further...
Serialization is one of those things you can easily do without until all of a sudden you really need it one day. Once you do look into it, it seems to be useful all the time. Let's have a look at the serialization options we have available to us in Ruby.
The concept of private, protected and public methods in Ruby is somewhat different than it is in languages like Java, it's all about which object is the receiver of a particular method call. Let's take a closer look at how access control works in Ruby.
We can demonstrates the value of recursion by using Ruby to solve the Towers of Hanoi puzzle both iteratively and recursively. As a side-effect this shows how much more expressive the solution can be when done in Ruby.
I recently decided to play around with writing a ruby quine (especially since there didn't seem to be many around). Along with discussing the possible merits of quines as an interview question, here is what I came up with.
I've recently been looking at timing bits of Ruby code as they were executing. Here is what I learned
In my previous post on boolean search, we wrote an efficient list (array) intersection function. But, to be honest, I wasn’t very happy with it. Considering the fact that we were using Ruby, it just wasn’t very Ruby-like. So, this time I am going to try and show how that function can be re-written to make it more Ruby-ish and to also be tighter and easier to understand.
Ruby on Rails projects usually use MySQL or PostgreSQL for their database, but in the corporate world, Oracle is king. As much as you might like to have a Postgres backend, the powers-that-be have decreed and you must obey. Don't worry though, all is not lost, you don't have to slink back to Java, here is how you can get your Rails app working with an Oracle database and deploy it all to Tomcat as a Java webapp if that wasn't enough.
I was trying to fetch some RSS feeds with Ruby the other day. I just needed something quick to validate a couple of things I was trying out with Rails. However it seems that the Ruby ecosystem has this natural hatred for corporate proxies, it’s come to bite me time and time again. But I wasn't giving up without a fight, so lets see what we can do about our proxy problems and fetch some feeds.
If you’re into Ruby and are not yet using RVM (ruby version manager) you’re doing yourself a disservice. It’s a great little tool that allows you to easily have multiple Ruby installs on the one machine and will manage all the associated complexity for you. Here is a quick intro to get you started with rvm.
Ruby exceptions and error handling is not the most remarkable feature of the Ruby language. Infact, the way Ruby deals with exceptions is strikingly similar to other languages (such as Java etc.). But, I think all the stuff I’ve been writing about Ruby lately has taken on a life of it’s own for me :), so I am going to quickly go over this topic if only for completeness sakes. Hope you enjoy Ruby Exceptions And Exception Handling.
Object comparison is extremely important, not only do we tend to often explicitly compare objects to each other but objects are frequently compared and tested for equality ‘behind the scenes’, by core and library classes (i.e. ordering of objects in collections etc.). When it comes to object equality Ruby is interesting in that it provides multiple methods to test for object equality each with a slightly different purpose. So, lets not waste any time and jump straight into Ruby Equality And Object Comparison.
Every expression and object in Ruby has a boolean value. True, false and nil are special in that they are not only keywords but are also objects which means we can do some interesting things with them.
I recently covered Ruby block basics in my post, More Advanced Ruby Method Arguments – Hashes And Block Basics. I mentioned that blocks are not really method arguments and also covered the two different types of block syntax. Towards the end of that post I promised to examine Ruby blocks more deeply and I am going to do that here. In my opinion there are several interesting things about blocks...
I remember when I first started looking at Ruby, I’d be browsing some code and see yet another way of looping/iterating over stuff. Whenever that would happen I would think, “…Ruby sure has a lot of different ways to iterate over things”, but I also remember wishing that someone would just put all the different ways to loop and iterate over stuff together so that you don’t have to discover them in a piecemeal fashion. So, I’ve decided to fulfill my own wish and put together all the different ways to loop over stuff in Ruby...
I’ve previously given an overview of basic method arguments in Ruby. There is quite a lot you can do with just the basic method arguments, so I purposely left out the more advanced topics from that post (which many people were quick to point out :)). However, if you want to have an in-depth knowledge of Ruby you will need to know about More Advanced Ruby Method Arguments (Hashes And Block Basics) and this is what I am going to cover here.
I found case statements in Ruby pretty interesting as they are capable of doing a little more than the equivalent constructs in other languages. How A Ruby Case Statement Works And What You Can Do With It is the result of me digging into it a little bit.
Digging a little more deeply into Method Arguments In Ruby and how optional and required arguments mix.
The Most Handy NetBeans Shortcuts For Ruby Development - just a quick list of all the shortcuts that I've been finding handy while using NetBeans for Ruby development.
Digging Into A Ruby Installation, Require vs Load And Other Stuff tries to dig a little bit more deeply into the basic anatomy of a ruby installation and how Ruby discovers libraries at runtime.
Installing And Using SQLite With Ruby On Windows - SQLite is a great little embeddable database engine that’s meant to be self-contained, easy to use and not require configuration. However when I tried to use it in my Ruby code I found that it wasn’t that straight forward getting everything to work, especially if you’re using Ruby on windows.
How To Write A Simple Web Crawler In Ruby - takes you through what you need to know to write a simple web crawler in Ruby from scratch (all code is included). It also mentions some of the ways the web crawler can be made more useful and robust.