Object Relational Mapper
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
#!/usr/bin/env ruby | |
require 'xmlsimple' | |
require 'active_support/inflector' | |
require 'yaml' | |
require 'json' | |
require 'fileutils' | |
require 'date' | |
class Post |
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 smiley(feel = {mood: "happy", mood: "sad", mood: "weird"}) | |
if | |
feel == {"mood" => "happy"} | |
":)" | |
elsif | |
feel == {"mood" => "sad"} | |
":(" | |
else | |
feel == {"mood" => "weird"} | |
":|" |
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
stupid ruby tricks | |
Posted by Nick Quaranto | |
# Over the past few months of slinging Ruby here at Thoughtbot, I’ve picked up quite a | |
# few stupid ruby tricks smart ruby techniques that really help out your code. | |
# If you’ve got your own, feel free to leave a comment. | |
# Destructuring yielded arrays | |
def touch_down |
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
# Define a method and accept an unspecified number of arguments and insert them into an | |
# array called coords. The array is created with the "*". | |
def print_grid_1a(*coords) | |
# Create an array called grid consisting of 5 elements each with a string | |
# consisting of 5 O's | |
grid = Array.new(5) {"O" * 5} | |
# Assign the variable x to the first element of the coords array and y to the second | |
x, y = coords | |
# Change the O to an X in the x indexed character inside the string ("OOOOO") | |
# that is in the y element of the grid array |
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
# http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html | |
class Learn | |
def initialize(*arguments) | |
@var1, @var2 = arguments | |
end | |
def method | |
"#{@var1} #{@var2}" | |
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 Shape | |
attr_reader :color | |
def initialize(color) | |
@color = color | |
end | |
def can_fit?(shape) | |
self.area < shape.area ? true : false | |
end |
OlderNewer