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|
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|
headers = nil | |
File.foreach(path) do |line| | |
fields = line.split(“|”) | |
if headers | |
row = headers.zip(fields) | |
# … | |
else | |
headers = fields | |
end | |
end |
use std::fmt; | |
use std::os; | |
struct Stack { | |
numbers: Vec<f64> | |
} | |
impl Stack { | |
fn new() -> Stack { | |
Stack{numbers: vec![]} | |
} |
// 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 |
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); | |
} |
// The uncommented version of increment_all() works. What I'm trying to | |
// understand is why I can't handle the return type as shown in the commented | |
// out version, which does not compile. | |
// fn increment_all<I: Iterator<int>>(numbers: I) -> I /* or Iterator<int> */ { | |
fn increment_all<'r, I: Iterator<int>>(numbers: I) -> std::iter::Map<'r, int, int, I> { | |
numbers.map(|n| n + 1) | |
} | |
fn main() { |
use std::collections::HashMap; | |
fn main() { | |
let mut services = HashMap::new(); | |
services.insert("S1", vec!["A", "C"]); | |
for (name, stops) in services.iter() { | |
spawn( proc() { | |
println!("{}", name); | |
} ); |
class HashLike | |
def to_hash | |
{a: 1, b: 2} | |
end | |
end | |
def surprise(*args, keyword: nil) | |
p args | |
end |
require "minitest/autorun" | |
class Something | |
def dont_do_it | |
:oops | |
end | |
end | |
class RetryTest < Minitest::Test | |
def test_different_return_values |
>> s = "active_model/errors" | |
=> "active_model/errors" | |
>> i = 0 | |
=> 0 | |
>> while (md = s.match(/(?:_|(\/))([a-z\d]*)/i, i)); s[md.begin(0)...md.end(0)] = "#{md[1]}#{md[2].capitalize}"; i = md.end(0) - 1 end | |
=> nil | |
>> s | |
=> "activeModel/Errors" |