Skip to content

Instantly share code, notes, and snippets.

View mariorcardoso's full-sized avatar

Mario Cardoso mariorcardoso

View GitHub Profile
{
"name": "rails_webpack_npm_es6",
"version": "1.0.0",
"main": "app-js/main.js",
"scripts": {
"heroku-postbuild": "webpack"
},
"repository": {
"type": "git",
"url": "https://github.com/mariorcardoso/rails_webpack_npm_es6.git"
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
'babel-polyfill',
'./app-js/main',
],
output: {
path: __dirname + '/app/assets/javascripts',
import { Rectangle } from './rectangle'
import { Square } from './square'
import { Circle } from './circle'
import { CanvasLibrary } from './canvas_library'
$(document).ready(function() {
const canvas = new CanvasLibrary();
const layer = canvas.get_layer();
const stage = canvas.get_stage();
class Rectangle {
constructor(height, width, color) {
this.height = height
this.width = width
this.color = color
}
draw(layer, stage) {
const rectangle = new Konva.Rect({
x: Math.random() * stage.getWidth(),
@mariorcardoso
mariorcardoso / date_range.rb
Last active June 25, 2017 11:44
Code samples about value objects
class DateRange
attr_reader :start_date, :end_date
def initialize(start_date, end_date)
@start_date, @end_date = start_date, end_date
end
def include_date?(date)
date >= start_date && date <= end_date
end
class Event < ActiveRecord::Base
def date_range
DateRange.new(start_date, end_date)
end
def date_range=(date_range)
self.start_date = date_range.start_date
self.end_date = date_range.end_date
end
end
class Person < ActiveRecord::Base
def address
Address.new(address_city, address_state)
end
def address=(address)
self.address_city = address.city
self.address_state = address.state
end
end
class Address
attr_reader :city, :state
def initialize(city, state)
@city, @state = city, state
end
def ==(other_address)
city == other_address.city && state == other_address.state
end
> gary = Person.create(name: "Gary")
> gary.address_city = "Brooklyn"
> gary.address_state = "NY"
> gary.address
=> #<Address:0x007fcbfcce0188 @city="Brooklyn", @state="NY">
> gary.address = Address.new("Brooklyn", "NY")
> gary.address
=> #<Address:0x007fcbfa3b2e78 @city="Brooklyn", @state="NY">
class Grade
include Comparable
attr_reader :percentage
def initialize(percentage)
@percentage = percentage
end
def better_than?(other)
self > other