Is there any built-in method in RoR to fill zero for integer?
If I want "00001" instead of "1", apart from writing my own filling zero method, is there any built in method can help me fill in zero for the integer? ...
If I want "00001" instead of "1", apart from writing my own filling zero method, is there any built in method can help me fill in zero for the integer? ...
I can do this myself of course, but is there built-in functionality in Ruby, or a library, that would let me do something like this date = Time.now sunday = date.week.first_day saturday = date.week.last_day Thanks ...
How could I have the output of say the unix 'ls' (Desktop, Pictures, Music myysong.mp3 etc) be converted to a string?? thx in advance ...
I have a table which should store an id, a name and a hash. How do I serialize the Hash? (I'm using Ruby and Sequel as ORM.) ...
In ruby 1.9 there is a way to define this hash with the new syntax? irb> { a: 2 } => {:a=>2} irb> { a-b: 2 } SyntaxError: (irb):5: syntax error, unexpected tLABEL { a-b: 2 } ^ with the old one, it's working: irb> { :"a-b" => 2 } => {:"a-b"=>2} ...
I need to archive multiple files using ruby, but I need to archive them in such way that they could be extracted without using my script (so I need popular format). Problems with tar are max file length and problems with random file access while writing tar. Good pure ruby library or ruby binding is highly desirable. Built-in compress...
I'm trying to port over some of my old rails apps to Ruby 1.9 and I keep getting warnings about how "Ruby 1.9 doesn't support Unicode normalization yet." I've tracked it down to this function, but I'm getting about 20 warning messages per request: rails-2.3.5/activesupport/lib/active_support/inflector.rb def transliterate(string) wa...
Hi, I've 2 models class Room < ActiveRecord::Base has_many :people accepts_nested_attributes_for :people, :reject_if => lambda { |a| a[:person_id].blank? }, :allow_destroy => true end class Person < ActiveRecord::Base belongs_to :room end In '/rooms/new' form I've a select tag containing all Person + an 'other' option tag that...
Please Note: Portable as in portableapps.com, not in the traditional sense of a language that can be used on multiple architectures or operating systems. Whoever coined this usage of the word portable should be whacked. :) I'm a DBA and sysadmin, mostly for Windows machines running SQL Server. I'm looking for a programming/scripting lan...
Take the following code: ### Dependencies require 'rubygems' require 'sinatra' require 'datamapper' ### Configuration config = YAML::load(File.read('config.yml')) name = config['config']['name'] description = config['config']['description'] username = config['config']['username'] password = config['config']['password'] theme = config[...
I'm trying to add logging to a method from the outside (Aspect-oriented-style) class A def test puts "I'm Doing something..." end end class A # with logging! alias_method :test_orig, :test def test puts "Log Message!" test_orig end end a = A.new a.test The above works alright, except that if I ever needed to do...
I'm trying to create an application that will primarily consist of ruby scripts that will be run from the command-line (cron, specifically). I want to have a libs folder, so I can put encapsulated, reusable classes/modules in there, and be able to access them from any script. I want to be able to put my scripts into a "bin" folder. W...
Well, add me to the list of Python programmers who are falling in love with Ruby but have a lingering PyAddiction. Like the post about Python's getattr, I'm looking for the Ruby equivalent of doing this: setattr(obj, 'attribute', value) where obj is an object instance, attribute is the name of one of the object's attributes as a strin...
I am new to CouchDB way of making things. So, I have a lot of questions about it, but let's focus in one of them. CouchDB has this concept of javascript code (validation + map-reduce + show + ?) being written in the design documents. This is part of the database, like stored procedures or triggers are for more tradittional databases. I...
I am starting to learn Ruby on Rails. I have an application in mind that I would like to create, but I know I'm going to have to repeat a lot of the things that have already been done a million times (such as user authentication, etc). I just found out about rails templates. From what I understand, you can use one of these templates to ...
I've run into the following issue while trying to execute some git commands from within a Ruby rake task (I've tried without the bash --login -c and get the same result). tmpid='TueJan26014125UTC2010' cmd=["git add .", "git commit -a -m \'Migrate nanoc3 co output to gh-pages #{tmpid}\'", "git push --force origin gh-pages:gh-pages" ]...
I'm getting started with Ruby on Rails. I think some cheat sheets or reference cards would really help me to get started (specifically, with migrations). Do you know of any cheat sheets or reference cards that would help me get started? ...
I'm trying a basic RSpec / Cucumber tutorial given here However, when I run the command "script/cucumber features", I get the following error and am not able to proceed further. Using the default profile... uninitialized constant Spec::Example (NameError) /home/badal/NetBeansProjects/blog/vendor/rails/activesupport/lib/active_support/d...
I'm trying to make a little class in ruby allowing me to make a system tray icon and use the notification balloons. But I'm having problems using structs with Win32API calls. http://www.ruby-forum.com/topic/18102 Shell_NotifyIcon Function NOTIFYICONDATA Struct Heres the code I have now, all it does is add an icon to the system tray: r...
In Ruby, we could use super within singleton method to call the corresponding super class's singleton method, like the following code shows. class Base def self.class_method puts "Base class method" end end class Derived < Base def self.class_method puts "Derived class method" super end end Derived.class_method # D...