App has 4 keys in a hash property called stats
: '10s', '1min', '5min', 'day'. Each are arrays of Stat objects
In order to create a stats
attribute in AppSerializer, we have to create an
intermediary Serializer with the attributes in order to re-use StatSerializer
for each of those four Stat collections, and the syntax within that Serializer
is pretty kludgy to make the association work.
This file contains hidden or 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
#include <iostream> | |
#include <mruby.h> | |
#include <mruby/proc.h> | |
#include <mruby/compile.h> | |
void eval_expanded(mrb_state *mrb, char code[]) { | |
struct mrb_parser_state *p; | |
mrbc_context *context = mrbc_context_new(mrb); | |
p = mrb_parse_string(mrb, code, context); | |
This file contains hidden or 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
begin | |
platform_detection | |
rescue OSXFoundError | |
osx_specific_initializer | |
rescue WindowsFoundError | |
windows_specific_initializer | |
rescue UnixFoundError | |
unix_specific_initializer | |
ensure | |
universal_initializer |
This file contains hidden or 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
require 'yaml' | |
equipment = YAML.load_file('equipment.yml') | |
weapons = equipment['weapons'] | |
armor = equipment['armor'] | |
puts weapons[1][1] # => { 'name' => 'Long Sword', 'damage' => 7 } |
This file contains hidden or 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
module BracketGenerator | |
class Node < Struct.new(:left, :right, :position, :depth, :render) | |
def initialize | |
self.render = true | |
end | |
def add | |
self.left = Node.new | |
self.right = Node.new | |
end |
This file contains hidden or 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 Dog | |
def speak | |
"woof" | |
end | |
end | |
class Cat | |
def speak | |
"fuck you" | |
end |
This file contains hidden or 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
require 'spec_helper' | |
module Bar | |
def bar ; end | |
end | |
class Foo | |
include Bar | |
end |
This file contains hidden or 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
rails_env = ENV['RAILS_ENV'] || 'production' | |
app = 'my_awesome_app' | |
# 4 workers and 1 master | |
worker_processes (rails_env == 'production' ? 4 : 1) | |
# Load rails+github.git into the master before forking workers | |
# for super-fast worker spawn times | |
preload_app true |
This file contains hidden or 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
# This is a problem with an array of Hash objects wherein each Hash object | |
# needs to be manipulated rather than all keys serialized. | |
# | |
# @bracket.class # => Bracket | |
# @bracket.seats.class # => Array | |
# @bracket.seats[0].class # => Hash | |
# @bracket.seats[0].keys # => ['position','round', 'won'] | |
class BracketSerializer < ActiveModel::Serializer | |
attribute :final_size, key: :size |