I have a problem that pretty much boils down to this:
a = [1, 2, 3]
b = [1.1, 2.2, 3.3]
# BEGIN GROSS SOLUTION: avert your eyes!
results = [ ]
a.each do |i|
b.each do |j|
fn increment(numbers: &Vec<int>) -> Vec<int> { | |
numbers.iter().map(|n| n + 1).collect() | |
} | |
fn main() { | |
let before = vec![1i, 2, 3]; | |
let after = increment(&before); | |
println!("{}", after); | |
} |
// I'm trying to make sure I have my head around "lifetimes" | |
// after a few readings of the guide: | |
// http://doc.rust-lang.org/guide-lifetimes.html. The following is | |
// a simple example of what I think I now know that I'll try to explain | |
// in this comment. | |
// | |
// Because the letters are "borrowed references," (Do I have my terms right?) | |
// they could potentially be freed before the Lists struct that contains them. | |
// Since this possibility exists, Rust requires the explicit lifetime 'a which | |
// indicates that the lifetime of a created Lists instance is tied to whatever |
use std::fmt; | |
use std::os; | |
struct Stack { | |
numbers: Vec<f64> | |
} | |
impl Stack { | |
fn new() -> Stack { | |
Stack{numbers: vec![]} | |
} |
headers = nil | |
File.foreach(path) do |line| | |
fields = line.split(“|”) | |
if headers | |
row = headers.zip(fields) | |
# … | |
else | |
headers = fields | |
end | |
end |
I have a problem that pretty much boils down to this:
a = [1, 2, 3]
b = [1.1, 2.2, 3.3]
# BEGIN GROSS SOLUTION: avert your eyes!
results = [ ]
a.each do |i|
b.each do |j|
~/Desktop [ruby 2.0.0p247]$ cat dont_close_my_logger.rb | |
require "logger" | |
log = ARGV.shift or abort "USAGE: #{$PROGRAM_NAME} LOG" | |
logger = Logger.new(log) | |
threads = [ ] | |
threads << Thread.new do | |
logger.info "Thread one started. Sleeping a bit to make sure thread two is going..." | |
sleep 1 |
class RequiredArgument | |
def initialize(one, keyword: false) | |
p [one, keyword] | |
end | |
end | |
RequiredArgument.new(Hash.new) | |
# ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0] | |
# bug.rb:2:in `initialize': wrong number of arguments (0 for 1) (ArgumentError) |
(set-face-attribute 'window-number-face nil :background "#2a2a2a") | |
(set-face-attribute 'window-number-face nil :foreground "red") |
I've been in multiple discussions lately about the problems with subclassing Ruby's base types.
The main problem is that Ruby sometimes takes shortcuts with the base types, for performance reasons. This can cause them to behave odd. For example, have a look at this subclass:
class MyString < String
def initialize(*)
super
puts "Building MyString: #{inspect}"
end