Hi,
Am I missing something in the Array documentation? I have an array which contains up to one object satisfying a certain criterion. I'd like to efficiently find that object. The best idea I have from the docs is this:
candidates = my_array.select { |e| e.satisfies_condition? }
found_it = candidates.first if !candidates.empty?
B...
I have the following Ruby code:
Testcase.rb:
filename = "/absolute/path/to/Untrusted.rb"
thread = Thread.new do
$SAFE = 4
Kernel::load(filename, true)
end
thread.join
Untrusted.rb
#Untrusted code
puts "Untrusted!"
However, I get an error when I try to run Testcase.rb:
/Volumes/Data/Users/mike/Desktop/Testcase.rb:4:in `write':...
I'm trying to generate a self-signed certificate in ruby, but am running into trouble. This is what I currently have right now:
require 'openssl'
if ARGV.length != 3 then
puts "USAGE: #{__FILE__} <type[der|pem]> <private-out> <public-out>"
exit
end
type = ARGV[0].downcase
privateKeyFile = ARGV[1]
publicKeyFile = ARGV[2]
valu...
Hi,
In learning ruby on rails I've created a blog site. When the user adds a post via AJAX, the following rjs gets called:
page.replace_html 'posts', :partial => @posts
page.visual_effect :Highlight, 'post_' + @post.id.to_s
However, the highlight isn't happening.. neither is any sort of effect even a hide.
Clues:
It works if I ju...
Ruby-debug is getting hung up by breaking on the "break" ruby reserved word on line 94 activesupport-2.3.5/lib/active_support/callbacks.rb.
def run(object, options = {}, &terminator)
enumerator = options[:enumerator] || :each
unless block_given?
send(enumerator) { |callback| callback.call(object) }
else
send(e...
Anyone know how to get this to work if it's possible?
class Foo
def self.go(&block)
class << block
include Bar
end
puts "Within Foo#go: #{block.methods.include? 'baz'}"
block.call
end
end
module Bar
def baz
puts "I'm happily in my place!"
end
end
Foo.go {
puts "Within actual block: #{methods.in...
Anyone seen any tangible metrics or sites that talk about the percentages of Rails apps in production that are using Ruby 1.8 vs Ruby 1.9?
In other words, we're contemplating back support for 1.8 but want to know if it's really worth it.
Thanks!
Chad
...
I'm using the Ruby official Ruby C interface and am not able to bzip working. It did build with bzip support, ./configure said:
checking bzlib.h usability... yes
checking bzlib.h presence... yes
checking for bzlib.h... yes
So I wrote this example program that just writes an entry to two files, one supposedly bzip'd and one not. Neithe...
So I'm extending a friend's project and he's done all the development with TDD using Test::Unit
I use Rspec in all my projects and want to avoid having to learn a new tool. Is it bad practice to have 2 separate test suites, one in Test::Unit and one in Rspec?
I've also considered using Shoulda to extend Test::Unit to sort of feel like ...
Would someone be able to break down the Ruby specifics of what each of these statements consist of in as far as methods, parameters, block interpretations etc. This is very common to see in Rails code and I'm trying to understand how the Ruby interpreter reads this code:
respond_to do |format|
format.xml { render :layout => false }
en...
Hi,
I need to strip the created_at and updated_at fields from an instance before it's serialised and pushed to a client. What is the neatest way to achieve this?
Thanks,
Chris
...
I have a very complex controller with a very complex set of views and partial views that I'm trying to clean up (not written by me originally).
In the controller, it defines member variables, like:
@blah = "blah"
which I'm not sure if they are used in a view, or a partial view, or a partial view called by a partial view. Is there any...
Has anybody here successfully installed the system_timer gem on Windows?
I have devkit on my machine and I am able to install other native gems.
I get the following error when I install the gem.
In file included from system_timer_native.c:2:
c:/Ruby19/include/ruby-1.9.1/ruby/backward/rubysig.h:14:2: warning:
#warning rubysig.h is o...
This is lengthy, yes, I apologize. But I want to be clear because this issue is so odd.
I have a terms of service modal that comes up whenever a user has not accepted our terms of service (TOS). For the purposes here, javascript is turned off and what is rendered is strictly html/css. So the page, if thought of in 3 layers, is: bottom l...
Hi there, I'm working on a newly configured computer, and can't seem to get rails to play nicely with my gems. Below are some of the errors I'm running into.
If I run 'script/console' in a rails project, I get the following error:
Missing the Rails gem. Please gem install -v= rails, update your RAILS_GEM_VERSION
setting in conf...
I have a Card class and I want to overload the > operator to compare against another card (Ace is higher than king, king higher than queen, etc). I've forgotten what little I ever knew about Ruby and don't have a clue where to start.
class Card
@@RANKS = ['A', 'K', 'Q', 'J', 'T', '9', '8','7','6','5','4','3','2']
attr_reader :rank
...
I am looking to generate ruby modules from existing C libraries.
In the past, I have used Swig, and found that it was a painful task. I just want to check if there's something better for Ruby out there, and any gotchas.
Just need to evaluate choices, so even a simple url pointing me to the site will do!
...
I'm working on a system than has to be pretty scalable from the beginning. I've started looking at / playing around with asynchronous/evented approaches to writing serverside code. I've played around with both ruby's EventMachine and node.js.
EventMachine is cool, but doesn't have asynchronous file I/O, which I need. The interface is ki...
Hello,
Just thinking about the best way to build an Order form that would (from user-perspective):
Allow adding multiple items.
Each item has Name, Job Type drop-down and File upload.
User can add or remove items.
User must provide at least one item.
All the items should be validated (eg: Name, JobType and File are required).
When he ...
Just asked how to check if an internet connection exists using javascript and got some great answers. What's the easiest way to do this in Ruby? In trying to make generated html markup code as clean as possible, I'd like to conditionally render the script tag for javascript files depending on whether or not an internet condition. Some...