This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THANKS TO https://rustbyexample.com/std/box.html | |
// for the code that was modified into this example | |
struct Point { | |
x: f64, | |
y: f64, | |
} | |
struct Rectangle { | |
p1: Point, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rand; | |
mod node; | |
mod helpers; | |
fn recursive_count_fruit(node: Option<Box<node::Node>>) -> i32 { | |
match node { | |
Some(val) => { | |
let our_fruit = if val.has_fruit { 1 } else { 0 }; | |
let unboxed = *val; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use helpers; | |
use std::fmt; | |
#[derive(Debug)] | |
pub struct Node { | |
pub left_child: Option<Box<Node>>, | |
pub right_child: Option<Box<Node>>, | |
pub has_fruit: bool, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def does_it_change | |
mutable_array = [1,2] | |
hash = {} | |
hash[mutable_array] = 'foo' | |
puts hash[mutable_array].inspect # prints "foo" | |
mutable_array[1] = 3 | |
puts hash[mutable_array].inspect # prints "nil" | |
end | |
does_it_change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace array_compare | |
{ | |
class Program | |
{ | |
static void DoesItChange() | |
{ | |
Dictionary<int[], string> hash = new Dictionary<int[], string>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stubbable | |
def stub(name, block) | |
send(:define_singleton_method, name, block) | |
end | |
end | |
class Class | |
def stub(name, block) | |
send(:define_singleton_method, name, block) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CSharpStyle | |
def method_missing method_name, *args | |
self.class.send(method_name, *args) | |
end | |
def self.static_method | |
puts "hurray for Ruby" | |
end | |
def instance_method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApplication | |
{ | |
public class HasInstanceAndStaticMethods | |
{ | |
public static void StaticMethod() | |
{ | |
Console.WriteLine("Hello from static method"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HasInstanceMethods | |
def instance_method | |
puts "In instance method, the type of `self` is #{self.class}" | |
end | |
def self.class_method | |
puts "In class method, the type of `self` is #{self.class}" | |
end | |
def call_class_from_instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# All Vagrant configuration is done below. The "2" in Vagrant.configure | |
# configures the configuration version (we support older styles for | |
# backwards compatibility). Please don't change it unless you know what | |
# you're doing. | |
Vagrant.configure("2") do |config| | |
config.vm.box = "ubuntu/trusty64" |