Why is the ":nodoc:" syntax needed?
It seems a lot of libraries/plugins use this syntax: def self.included(base) # :nodoc: base.extend ClassMethods end Why is the :nodoc: part necessary? ...
It seems a lot of libraries/plugins use this syntax: def self.included(base) # :nodoc: base.extend ClassMethods end Why is the :nodoc: part necessary? ...
I am using SWIG to wrap a C interface in Ruby. Given two structs typedef struct Vertex { int color, discoverd, finished; struct Vertex *next; } Vertex; typedef struct Graph { struct Vertex *vertex; } Graph; how can I create a #each method which yields the current vertex, so that I can process it in Ruby. Currently my SWIG inte...
I'me using Notepad++ for editing rake files and I'd like to be able to use the function list plugin. I've been unable to find any parsing rules on line, and the "Language Parsing Rules" dialog is not very clearly documented. I'm parsing methods into the list with the following, but would like to also display tasks. Function Begin: [...
I always do this to test string equality in Ruby: if mystring.eql?(yourstring) puts "same" else puts "different" end Is this is the correct way to do this without testing object equality? I'm looking for the most concise way to test strings based on their content. With the parentheses and question mark, this seems a little clunky...
To return a file using sinatra, I had been using this: get '/:name' do x = File.open('c:/mywebsite/' + params[:name],'r') end where the incoming url is "http://localserver:4567/myfile.html. It works, but it occurs to me there must be a better way, yet I can't find the preferred mechanism on the sinatra site. ...
Is this syntax functionally equivalent def self.included(base) base.class_eval do extend ClassMethods end end to this? def self.included(base) base.extend ClassMethods end ...
I've tried and tried, but I can't make this less ugly/more ruby-like. It seems like there just must be a better way. Help me learn. class Df attr_accessor :thresh attr_reader :dfo def initialize @dfo = [] @df = '/opt/TWWfsw/bin/gdf' case RUBY_PLATFORM when /hpux/i @fstyp = 'vxfs' wh...
This is really racking my brain, but maybe I'm trying to hard. I'm passing a param via a URL (example.com?debug=true) So I basically want to say: if params[:debug] == true do xyz else do abc end But for whatever reason that if statement just isn't doing like it seems like it should. Is there a better way to do that if/else statem...
In my application, I have the need to allow blocks to be defined and called within the scope of a class, using instance_exec (via Rails 2.3.2). However, some of these blocks need to return early in some situations, which is causing me a problem. My application was built using ruby 1.8.6, but I need to get it running on 1.8.7 as well. It...
I'm writing a project at the moment in Ruby which makes use of the ActiveRecord gem for database interaction and I'm trying to log all the database activity using the ActiveRecord::Base.logger attribute with the following code ActiveRecord::Base.logger = Logger.new(File.open('logs/database.log', 'a')) This works fine for migrations et...
I know that i can generate random floats with rand(max). I tried to generate a float in a range, this shouldn't be hard. But e.g rand(1.4512) returns 0, thus rand isn't calculating with floats. Now i tried a little trick, converting the thing to an integer and after randomizing a fitting number in my desired range, calculating it back to...
Hi, i have following code class Category < ActiveRecord::Base has_many :categorizations has_many :posts, :through => :categorizations end class Post < ActiveRecord::Base has_many :categorizations has_many :categories, :through => :categorizations end class Categorization < ActiveRecord::Base belongs_to :post belongs_to :ca...
If I write this, everything works fine: class A < ActiveRecord::Base acts_as_taggable end But if I take acts_as_taggable and put it into a module that class A includes, I get an error: module B def self.included(base) base.class_eval do extend ClassMethods include InstanceMethods end end module ClassMethods...
I would like to create a rake task or something to clear the browser cache. The issue is, I am running a Flash app, and if I change the data, I more often than not need to reset the browser cache so it removes the old swf and can see the new xml data. How do you reset the browser cache with ruby? Or even more precisely, how can I only...
Is there a library that can open and search through a pdf file? Preferably in C, python or ruby... ...
Hi guys, this is a really stupid question but I have a deadline and I'm very nervous and I've tried everything. In fact it even worked for a second but I must have broken something. I have a default featured item that I want to be overridden any time I try to feature another item. I had it give an error before but I don't want it to err...
Hi, I have come across a very weird error. I'm on Solaris 10, using Ruby Enterprise Edition (ruby 1.8.6 (2008-08-08 patchlevel 286) [i386-solaris2.10]) with Rails 2.3.4. I have a very weird error. In irb: irb(main):001:0> require 'bigdecimal' => true irb(main):002:0> b = BigDecimal.new('123') => #<BigDecimal:834d0e8,'0.123E3',4(8)> ir...
Hi, I'd like to find good way to find some (let it be two) sentences in some text. What will be better - use regexp or split-method? Your ideas? As requested by Jeremy Stein - there are some examples Examples: Input: The first thing to do is to create the Comment model. We’ll create this in the normal way, but with one small diffe...
I wrote a small app with Sinatra and have some admin routes (/admin/new, admin/edit/2, ...) and want to protect them with a .htaccess prompt. Can somebody tell me how I do that? ...
I see a lot of stuff include ActiveRecord::XXXX::InstanceMethods extend ActiveRecord::XXXX::SingletonMethods I am unaware of the property or there working, just wanted a easy to understand answer. if it has a good reason to be used. ...