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 Object | |
def pat | |
if block_given? | |
yield self | |
else | |
self | |
end | |
end | |
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 'cinch' | |
require 'logger' | |
logger = Logger.new('irc.log', 'daily') | |
logger.level = Logger::INFO | |
def now | |
Time.now.strftime('%Y-%m-%d %H:%M:%S') | |
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
module Timesheets | |
class << self | |
def text_to_fragment_list(text:) | |
text.split(',') | |
end | |
def normalize_fragment_list(fragment_list:) | |
fragment_list.map(&:strip) | |
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 LinePresenter | |
def initialize(object) | |
@object = object | |
end | |
def to_s | |
"Office: #{@object.office}, Employee ID: #{@object.employee_id}, First name: #{@object.first_name}" | |
end | |
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 Line | |
attr_reader :line | |
def initialize(text) | |
@line = text | |
end | |
def office | |
values[2].strip |
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 'json' | |
UNITS = { | |
'unit_a' => 'kg.25', | |
'unit_b' => 'kg.15', | |
# ... | |
'unit_c' => 'kg.5', | |
} | |
STORE = { |
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
nome_file = 'quantita_rimasta.txt' | |
if File.exists?(nome_file) | |
quantita_rimasta = File.read('quantita_rimasta.txt').to_i | |
else | |
quantita_rimasta = 100 | |
File.write(nome_file, quantita_rimasta) | |
end | |
prodotto0 = 'cemento' |
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 version uses mem::replace() | |
use std::mem; | |
struct Fibonacci { | |
curr: uint, | |
next: uint, | |
} | |
impl Iterator<uint> for Fibonacci { |
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
# Given: | |
require 'active_record' | |
require 'sqlite3' | |
ActiveRecord::Base.establish_connection( | |
adapter: 'sqlite3', | |
database: 'mydbfile.sqlite' | |
) | |
ActiveRecord::Schema.define do | |
create_table 'users', force: true do |t| | |
t.string 'name' |
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 'rspec' | |
require 'date' | |
require 'ostruct' | |
class Person < OpenStruct | |
def age | |
now.year - birthday.year | |
end | |
def now |