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
--colour | |
-I app |
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 FakeInstagram | |
def self.client(opts = {}) | |
instagram_response = Hashie::Mash.new | |
instagram_response.images!.thumbnail!.url = "someawesomeimage.jpg" | |
OpenStruct.new(user_recent_media: [instagram_response]) | |
end | |
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 UniqueArray | |
def self.new(*arg) | |
result = arg.flatten.uniq | |
result.each do |n| | |
raise TypeError, "Sorry I only take numbers" if !n.is_a? Fixnum | |
end | |
end | |
end | |
class 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
For this problem you will be creating a Ruby class which behaves exactly like an array but will store only numbers, will store them in the order they were added and when adding new elements will ignore any duplicates. In this way it functions like a Ruby hash object in that each key has to be unique. | |
Here's an example: | |
# Creating an array from another array. Notice that only the first occurrence of the number 2 is kept | |
UniqueArray.new([1,2,0,6,2,11]) | |
=> [1,2,0,6,11] |
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
################ tattoo.rb ################# | |
class Tattoo < ActiveRecord::Base | |
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h | |
attr_accessible :name, :image, :user_id | |
has_many :comments | |
belongs_to :user | |
has_attached_file :image, styles: { :thumb => "200x150>", :normal => "600x450>", :large => "600x600>" }, :processors => [:cropper] |
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 CreateLocations < ActiveRecord::Migration | |
def self.up | |
create_table :locations do |t| | |
t.datetime :time | |
t.point :geom, :null => false, :srid => 4326, :with_z => true | |
t.float :speed | |
end | |
end | |
def self.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
class Message | |
def deliver_to(mailbox) | |
mailbox.new_mail(self) | |
end | |
end | |
class Mailbox | |
def initialize |
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
s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n" | |
def add_index(lines) | |
indexed_lines = [] | |
lines.each_line.with_index(offset = 1) do |line, index| | |
indexed_lines << "Line #{index}: #{line}" | |
end | |
indexed_lines | |
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
s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n" | |
def add_index(lines) | |
indexed_lines = [] | |
lines.each_line.each_with_index do |line, index| | |
indexed_lines << "Line #{index + 1}: #{line}" | |
end | |
indexed_lines | |
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
Factory.define :user do |u| | |
u.full_name 'John' | |
u.email '[email protected]' | |
u.password 'foobar' | |
u.password_confirmation 'foobar' | |
u.admin false | |
u.coach false | |
u.bio 'This is my short bio' | |
end |