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
require 'virtus' | |
module PersonAttributes | |
include Virtus.module | |
attribute :name, String | |
attribute :age, Integer | |
end | |
class PersonModel |
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 Foo | |
def self.macros(&block) | |
mod = Module.new | |
mod.module_eval do | |
ANSWER = 42 | |
end | |
self.const_set(:Macros, mod) | |
Macros.module_eval do | |
module_eval &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
Listening to Ruby Rogues I heard one of the panels claiming performance problems because too many objects where created on every request: | |
http://devchat.tv/ruby-rogues/186-rr-the-4-rules-of-simple-design-with-corey-haines | |
(Search for: immutability) | |
I was curious since I started using DDD patterns the number of classes and temporal objects have exploded. | |
The speaker mentions "a ton of new objects for every request", so I assume that "a ton" is about hundreds or thousand of objects within a large loop, long running loop, nothing to be concerned if it is just a linear sequence of actions for a response. |
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 ArrayAdapter | |
def initialize(array, &block) | |
raise 'Adapter is useless without a block' unless block_given? | |
@raw = array | |
@transformer = block | |
end | |
def each(&block) | |
# StackOverflow | |
# http://stackoverflow.com/q/27798855/253098 |
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
"""""""""""""""""""""""""""""""""""""""" | |
" Keywords | |
" important, more eye catching | |
syn keyword rubyTodo DANGER WARNING WAITING TODO contained | |
hi rubyTodo guifg=magenta ctermfg=magenta gui=bold | |
" less important, less striking | |
syntax keyword rubySharpBang SOURCES NOTE FUTURE DFS contained | |
hi rubySharpBang guifg=darkmagenta ctermfg=darkmagenta gui=bold |
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
require './b' | |
require './b.rb' |
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
require 'sprockets/../rake/sprocketstask' | |
RACK_ENV = ENV['RACK_ENV'] ||= ENV['RACK_ENV'] ||= 'production' unless defined?(RACK_ENV) | |
SPROCKETS='production' | |
Rake::SprocketsTask.new do |t| | |
manifest_path = File.expand_path('../public/assets/manifest.json', __FILE__) | |
t.environment = SPROCKETS | |
t.output = File.expand_path('../public/assets', __FILE__) | |
t.manifest = Sprockets::Manifest.new(SPROCKETS, manifest_path) | |
t.assets = %w(application.js application.css) |
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
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
watch: { | |
files: 'app/views/**/*.erb', | |
options: { | |
livereload: true, | |
} | |
} |
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
source 'https://rubygems.org' | |
#gem "rack-livereload", :group => :development | |
# Prevent Mac problems | |
gem "rb-fsevent" | |
gem "rb-readline" | |
gem "guard-livereload" | |
#gem "guard-spring", :group => :development |
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
❯ curl http://127.0.0.1:3000 | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<style type="text/css"> | |
body { text-align:center;font-family:helvetica,arial;font-size:22px; | |
color:#888;margin:20px} | |
#c {margin:0 auto;width:500px;text-align:left} | |
</style> |