Tag Archives: ruby

Singleton Classes

How can you create a singleton class in a Rails application? The same as in a Ruby application! Using Singleton gives you free functionality: it makes the constructor private, and it creates a static method called instance, to get the singleton instance. If you check equality for two singleton instances, they will always be equal. We discuss a brief example. Continue reading

Posted in Development | Tagged , | 2 Comments

Formatting Decimals

How can you format decimal-point (floating-point) numbers to a specific precision? Ruby has a sprintf function that allows you to do this. It takes a number and a string of a specific format, and returns the number rounded to the precision you specified. Continue reading

Posted in Development | Tagged , , , | 1 Comment

The Mysterious h Function

What is this mysterious h function? It encodes strings, so that special characters become HTML-compliant–it turns angle brackets, tabs, and other characters into HTML entities. You can use it partly for security, to avoid cross-site scripting and other security vulnerabilities! Continue reading

Posted in Development | Tagged , , | Comments Off

Ruby Crash-Course

So, you want to dive into your first Rails application! But Rails is only a framework–the underlying programming language is still Ruby. This crash course teaches you the basics of Ruby, enough to get your first Rails application rocketing to success! We go over variables, control-flow, comments, arrays, hashtables, and some useful functions for formatting. Continue reading

Posted in Development | Tagged , | Comments Off