repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/template_method/html_report.rb | template_method/html_report.rb | require_relative 'report'
class HTMLReport < Report
def output_start
puts '<html>'
end
def output_head
puts ' <head>'
puts " <title>#{@title}</title>"
puts ' </head>'
end
def output_body_start
puts '<body>'
end
def output_line(line)
puts " <p>#{line}</p>"
end
def out... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/template_method/plain_text_report.rb | template_method/plain_text_report.rb | require_relative 'report'
class PlainTextReport < Report
def output_start
end
def output_head
puts "**** #{@title} ****"
puts
end
def output_body_start
end
def output_line(line)
puts line
end
def output_body_end
end
def output_end
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/main.rb | abstract_factory/main.rb | require_relative 'colored_shape_factory'
colored_shape_factory = ColoredShapeFactory.new
red_circle_factory = colored_shape_factory.get_factory('RedCircle')
puts 'Red Circle Factory'
red_circle_factory.get_shape.draw
red_circle_factory.get_color.fill
puts
green_square_factory = colored_shape_factory.get_factory('Gre... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/green.rb | abstract_factory/green.rb | require_relative 'color'
class Green < Color
def fill
puts 'Inside Green::fill() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/blue.rb | abstract_factory/blue.rb | require_relative 'color'
class Blue < Color
def fill
puts 'Inside Blue::fill() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/green_square_factory.rb | abstract_factory/green_square_factory.rb | require_relative 'abstract_factory'
require_relative 'square'
require_relative 'green'
class GreenSquareFactory < AbstractFactory
def get_shape
Square.new
end
def get_color
Green.new
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/circle.rb | abstract_factory/circle.rb | require_relative 'shape'
class Circle < Shape
def draw
puts 'Inside Circle::draw() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/square.rb | abstract_factory/square.rb | require_relative 'shape'
class Square < Shape
def draw
puts 'Inside Square::draw() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/shape.rb | abstract_factory/shape.rb | class Shape
def draw
raise NotImplementedError
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/color.rb | abstract_factory/color.rb | class Color
def fill
raise NotImplementedError
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/rectangle.rb | abstract_factory/rectangle.rb | require_relative 'shape'
class Rectangle < Shape
def draw
puts 'Inside Rectangle::draw() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/blue_rectangle_factory.rb | abstract_factory/blue_rectangle_factory.rb | require_relative 'abstract_factory'
require_relative 'rectangle'
require_relative 'blue'
class BlueRectangleFactory < AbstractFactory
def get_shape
Rectangle.new
end
def get_color
Blue.new
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/colored_shape_factory.rb | abstract_factory/colored_shape_factory.rb | require_relative 'red_circle_factory'
require_relative 'green_square_factory'
require_relative 'blue_rectangle_factory'
class ColoredShapeFactory
def get_factory(factory_type)
if %w(RedCircle GreenSquare BlueRectangle).include? factory_type
self.class.const_get("#{factory_type}Factory").new
end
end
e... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/red_circle_factory.rb | abstract_factory/red_circle_factory.rb | require_relative 'abstract_factory'
require_relative 'circle'
require_relative 'red'
class RedCircleFactory < AbstractFactory
def get_shape
Circle.new
end
def get_color
Red.new
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/abstract_factory.rb | abstract_factory/abstract_factory.rb | class AbstractFactory
def get_color
raise NotImplementedError
end
def get_shape
raise NotImplementedError
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/abstract_factory/red.rb | abstract_factory/red.rb | require_relative 'color'
class Red < Color
def fill
puts 'Inside Red::fill() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/mediator/main.rb | mediator/main.rb | require_relative 'stock_offer'
require_relative 'colleague'
require_relative 'gorman_slacks'
require_relative 'jt_poorman'
require_relative 'stock_mediator'
# Stock exchange
nyse = StockMediator.new
# Stock Exchange Brokers
gorman_slack_broker = GormanSlacks.new(nyse)
jt_poorman_broker = JTPoorman.new(nyse)
# Tran... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/mediator/jt_poorman.rb | mediator/jt_poorman.rb | class JTPoorman < Colleague
def initialize(mediator)
super(mediator)
puts "JT Poorman signed up with the stockexchange\n"
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/mediator/stock_offer.rb | mediator/stock_offer.rb | class StockOffer
attr_accessor :stock_shares, :stock_symbol, :colleague_code
def initialize(stock_shares, stock_symbol, colleague_code)
@stock_shares = stock_shares
@stock_symbol = stock_symbol
@colleague_code = colleague_code
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/mediator/colleague.rb | mediator/colleague.rb | class Colleague
attr_accessor :colleague_code
def initialize(mediator)
@mediator = mediator
@mediator.add_colleague(self)
end
def sale_offer(stock, shares)
@mediator.offer_send(stock, shares, @colleague_code, :sale)
end
def buy_offer(stock, shares)
@mediator.offer_send(stock, shares, @co... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/mediator/stock_mediator.rb | mediator/stock_mediator.rb | class StockMediator
attr_accessor :colleagues, :stock_buy_offers, :stock_sale_offers, :colleague_codes
def initialize
@colleague_codes = 0
@colleagues = []
@stock_buy_offers = []
@stock_sale_offers = []
end
def add_colleague(colleague)
colleagues << colleague
@colleague_codes... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/mediator/gorman_slacks.rb | mediator/gorman_slacks.rb | class GormanSlacks < Colleague
def initialize(mediator)
super(mediator)
puts "Gorman Slacks signed up with the stockexchange\n"
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/main.rb | adapter/main.rb | require_relative 'encrypter'
require_relative 'decrypter'
require_relative 'string_io_adapter'
reader = File.open('message.txt')
writer = File.open('message.encrypted', 'w')
encrypter = Encrypter.new('XYZZY')
encrypter.encrypt(reader, writer)
reader.close
writer.close
reader = StringIOAdapter.new('We attack at dawn')... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/decrypter.rb | adapter/decrypter.rb | class Decrypter
def initialize(key)
@key = key
end
def decrypt(reader)
decrypted_message = ''
key_index = 0
until reader.eof?
encrypted_byte = reader.getbyte
key_byte = @key.getbyte(key_index)
decrypted_byte = (encrypted_byte ^ key_byte)
decrypted_message << decrypted_byte... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/encrypter.rb | adapter/encrypter.rb | class Encrypter
def initialize(key)
@key = key
end
def encrypt(reader, writer)
key_index = 0
until reader.eof?
encrypted_char = reader.getbyte ^ @key.getbyte(key_index)
writer.putc(encrypted_char)
key_index = (key_index + 1) % @key.size
end
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/string_io_adapter.rb | adapter/string_io_adapter.rb | class StringIOAdapter
def initialize(string)
@string = string
@position = 0
end
def getbyte
raise EOFError if @position >= @string.length
ch = @string.getbyte(@position)
@position += 1
ch
end
def eof?
@position >= @string.length
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/runtime_modifications/main.rb | adapter/runtime_modifications/main.rb | require_relative 'renderer'
require_relative 'text_object'
require_relative 'british_text_object'
# Extend the BritishTexObject to include the methods
# that the Renderer class requires
class BritishTextObject
def color
colour
end
def text
string
end
def size_inches
size_mm / 25.4
end
end
# ... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/runtime_modifications/british_text_object.rb | adapter/runtime_modifications/british_text_object.rb | class BritishTextObject < TextObject
attr_reader :string, :size_mm, :colour
# ...
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/runtime_modifications/Renderer.rb | adapter/runtime_modifications/Renderer.rb | class Renderer
def render(text_object)
text = text_object.text
size = text_object.size_inches
color = text_object.color
# render the text ...
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/adapter/runtime_modifications/text_object.rb | adapter/runtime_modifications/text_object.rb | class TextObject
attr_reader :text, :size_inches, :color
def initialize(text, size_inches, color)
@text = text
@size_inches = size_inches
@color = color
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/main.rb | strategy/main.rb | require_relative 'report'
require_relative 'html_Formatter'
require_relative 'plain_text_formatter'
report = Report.new(HTMLFormatter.new)
report.output_report
# Change the formatter at runtime
report.formatter = PlainTextFormatter.new
report.output_report
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/report.rb | strategy/report.rb | class Report
attr_reader :title, :text
attr_accessor :formatter
def initialize(formatter)
@title = 'Monthly Report'
@text = ['Things are going', 'really, really well.']
@formatter = formatter
end
def output_report
@formatter.output_report(self)
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/html_Formatter.rb | strategy/html_Formatter.rb | class HTMLFormatter
def output_report(context)
puts '<html>'
puts ' <head>'
puts " <title>#{context.title}</title>"
puts ' </head>'
puts ' <body>'
context.text.each do |line|
puts " <p>#{line}</p>"
end
puts ' </body>'
puts '</html>'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/plain_text_formatter.rb | strategy/plain_text_formatter.rb | class PlainTextFormatter
def output_report(context)
puts "***** #{context.title} *****"
context.text.each do |line|
puts line
end
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/using_procs/main.rb | strategy/using_procs/main.rb | require_relative 'report'
require_relative 'HTML_FORMATTER'
require_relative 'PLAIN_TEXT_FORMATTER'
report = Report.new(&HTML_FORMATTER)
report.output_report
# Change the formatter at runtime
report.formatter = PLAIN_TEXT_FORMATTER
report.output_report
# For added flexibility, we can use an on-the-fly code block as ... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/using_procs/report.rb | strategy/using_procs/report.rb | class Report
attr_reader :title, :text
attr_accessor :formatter
def initialize(&formatter)
@title = 'Monthly Report'
@text = ['Things are going', 'really, really well.']
@formatter = formatter
end
def output_report
@formatter.call(self)
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/using_procs/PLAIN_TEXT_FORMATTER.rb | strategy/using_procs/PLAIN_TEXT_FORMATTER.rb | PLAIN_TEXT_FORMATTER = lambda do |context|
puts "***** #{context.title} *****"
context.text.each do |line|
puts line
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/strategy/using_procs/HTML_FORMATTER.rb | strategy/using_procs/HTML_FORMATTER.rb | HTML_FORMATTER = lambda do |context|
puts '<html>'
puts ' <head>'
puts " <title>#{context.title}</title>"
puts ' </head>'
puts ' <body>'
context.text.each do |line|
puts " <p>#{line}</p>"
end
puts ' </body>'
puts '</html>'
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/factory/main.rb | factory/main.rb | require_relative 'shape_factory'
shape_factory = ShapeFactory.new
circle = shape_factory.get_shape('Circle')
circle.draw
rectangle = shape_factory.get_shape('Rectangle')
rectangle.draw
square = shape_factory.get_shape('Square')
square.draw
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/factory/shape_factory.rb | factory/shape_factory.rb | require_relative 'circle'
require_relative 'rectangle'
require_relative 'square'
class ShapeFactory
# Use getShape method to get object of type shape.
def get_shape(type)
case type
when 'Circle' then Circle.new
when 'Rectangle' then Rectangle.new
when 'Square' then Square.new
end
end
en... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/factory/circle.rb | factory/circle.rb | require_relative 'shape'
class Circle < Shape
def draw
puts 'Inside Circle::draw() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/factory/square.rb | factory/square.rb | require_relative 'shape'
class Square < Shape
def draw
puts 'Inside Square::draw() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/factory/shape.rb | factory/shape.rb | class Shape
def draw
raise 'must implement draw() method in subclass'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/factory/rectangle.rb | factory/rectangle.rb | require_relative 'shape'
class Rectangle < Shape
def draw
puts 'Inside Rectangle::draw() method.'
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/main.rb | interpreter/main.rb | require_relative 'parser'
# using parser
puts 'Interpreter patter using a parser'
puts 'Syntax: and(and(bigger 1024) (filename *.lock)) writable'
parser = Parser.new('and (and (bigger 1024) (filename *.lock)) writable')
ast = parser.expression
puts ast.evaluate('.')
puts
# parser-less interpreter
puts 'Interpreter pa... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/bigger.rb | interpreter/bigger.rb | require_relative 'expression'
class Bigger < Expression
def initialize(size)
@size = size
end
def evaluate(dir)
results = []
Dir.entries(dir).each do |e|
next unless File.file?("#{dir}/#{e}")
results << e if File.size(e) > @size
end
results
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/file_name.rb | interpreter/file_name.rb | require_relative 'expression'
class FileName < Expression
def initialize(pattern)
@pattern = pattern
end
def evaluate(dir)
results = []
Dir.entries(dir).each do |e|
next unless File.file?("#{dir}/#{e}")
base_name = File.basename(e)
results << e if File.fnmatch(@pattern, base_name)
... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/or.rb | interpreter/or.rb | require_relative 'expression'
class Or < Expression
def initialize(expression1, expression2)
@expression1 = expression1
@expression2 = expression2
end
def evaluate(dir)
results1 = @expression1.evaluate(dir)
results2 = @expression2.evaluate(dir)
(results1 + results2).sort.uniq
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/and.rb | interpreter/and.rb | require_relative 'expression'
class And < Expression
def initialize(expression1, expression2)
@expression1 = expression1
@expression2 = expression2
end
def evaluate(dir)
results1 = @expression1.evaluate(dir)
results2 = @expression2.evaluate(dir)
(results1 & results2).sort.uniq
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/parser.rb | interpreter/parser.rb | require_relative 'expression'
require_relative 'all'
require_relative 'file_name'
require_relative 'bigger'
require_relative 'writable'
require_relative 'not'
require_relative 'or'
require_relative 'and'
class Parser
def initialize(text)
@tokens = text.scan(/\(|\)|[\w\.\*]+/)
end
def next_token
@tokens.... | ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/not.rb | interpreter/not.rb | require_relative 'expression'
require_relative 'all'
class Not < Expression
def initialize(expression)
@expression = expression
end
def evaluate(dir)
All.new.evaluate(dir) - @expression.evaluate(dir)
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/writable.rb | interpreter/writable.rb | require_relative 'expression'
class Writable < Expression
def evaluate(dir)
results = []
Dir.entries(dir).each do |e|
next unless File.file?("#{dir}/#{e}")
results << e if File.writable?(e)
end
results
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/expression.rb | interpreter/expression.rb | class Expression
def |(other)
Or.new(self, other)
end
def &(other)
And.new(self, other)
end
end
def all
All.new
end
def name(pattern)
FileName.new(pattern)
end
def bigger(size)
Bigger.new(size)
end
def writable
Writable.new
end
def except(expression)
Not.new(expression)
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
design-patterns-in-ruby/design-patterns-in-ruby | https://github.com/design-patterns-in-ruby/design-patterns-in-ruby/blob/8464db28f24de3d666d7da5da51f84d8a27441e6/interpreter/all.rb | interpreter/all.rb | require_relative 'expression'
class All < Expression
def evaluate(dir)
results = []
Dir.entries(dir).each do |e|
next unless File.file?("#{dir}/#{e}")
results << e
end
results
end
end
| ruby | CC0-1.0 | 8464db28f24de3d666d7da5da51f84d8a27441e6 | 2026-01-04T15:54:29.970168Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/db/migrate/001_create_currencies.rb | app/db/migrate/001_create_currencies.rb | # frozen_string_literal: true
Sequel.migration do
change do
create_table :currencies do
Date :date
String :iso_code
Float :rate
index %i[date iso_code], unique: true
end
end
end
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/spec/api_spec.rb | app/spec/api_spec.rb | # frozen_string_literal: true
require_relative 'helper'
require 'rack/test'
require 'api'
describe 'the API' do
include Rack::Test::Methods
let(:app) { Sinatra::Application }
let(:json) { Oj.load(last_response.body) }
let(:headers) { last_response.headers }
it 'describes itself' do
get '/'
last_r... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/spec/edge_cases_spec.rb | app/spec/edge_cases_spec.rb | # frozen_string_literal: true
require_relative 'helper'
require 'rack/test'
require 'api'
describe 'the API' do
include Rack::Test::Methods
let(:app) { Sinatra::Application }
let(:json) { Oj.load(last_response.body) }
it 'handles unfound pages' do
get '/foo'
last_response.status.must_equal 404
... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/spec/currency_spec.rb | app/spec/currency_spec.rb | # frozen_string_literal: true
require_relative 'helper'
require 'currency'
describe Currency do
around do |test|
Currency.db.transaction do
test.call
raise Sequel::Rollback
end
end
before do
Currency.dataset.delete
@first = Currency.create(date: '2014-01-01')
@last = Currency.cr... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/spec/bank_spec.rb | app/spec/bank_spec.rb | # frozen_string_literal: true
require_relative 'helper'
require 'bank'
describe Bank do
around do |test|
Currency.db.transaction do
test.call
raise Sequel::Rollback
end
end
before do
Currency.dataset.delete
end
it 'fetches current rates' do
Bank.fetch_current_rates!
Currenc... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/spec/helper.rb | app/spec/helper.rb | # frozen_string_literal: true
require './config/environment'
require 'minitest/autorun'
require 'minitest/around/spec'
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/spec/quote_spec.rb | app/spec/quote_spec.rb | # frozen_string_literal: true
require_relative 'helper'
require 'quote'
describe Quote do
def stub_rates(default_rates = {})
quote.stub :find_default_rates, default_rates do
yield quote
end
end
describe 'by default' do
let(:quote) { Quote.new }
it 'quotes rates against the euro' do
... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/lib/currency.rb | app/lib/currency.rb | # frozen_string_literal: true
class Currency < Sequel::Model
dataset_module do
def recent
order(Sequel.desc(:date))
end
def before(value)
where { date <= value }
end
def current_date
recent.first&.date
end
def current_date_before(value)
before(value).current_dat... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/lib/quote.rb | app/lib/quote.rb | # frozen_string_literal: true
require 'currency'
class Quote
Invalid = Class.new(StandardError)
DEFAULT_AMOUNT = 1
DEFAULT_BASE = 'EUR'
attr_reader :amount, :base, :date, :symbols
def initialize(params = {})
self.amount = params['amount']
self.base = params.values_at(:base, :from).compact.first
... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/lib/bank.rb | app/lib/bank.rb | # frozen_string_literal: true
require 'currency'
require 'fixer'
module Bank
def self.fetch_all_rates!
Currency.db.transaction do
Currency.dataset.delete
data = Fixer.historical
Currency.multi_insert(data.to_a)
end
end
def self.fetch_current_rates!
Currency.db.transaction do
... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/lib/api.rb | app/lib/api.rb | # frozen_string_literal: true
require 'oj'
require 'sinatra'
require 'rack/cors'
require 'quote'
use Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: :get
end
end
configure :development do
set :show_exceptions, :after_handler
end
configure :production do
disable :dump_errors
... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/config/environment.rb | app/config/environment.rb | # frozen_string_literal: true
require_relative 'app'
$LOAD_PATH << App.root.join('lib')
Dir[App.root.join('config/initializers/*.rb')].each { |f| require f }
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/config/app.rb | app/config/app.rb | # frozen_string_literal: true
require 'pathname'
# Encapsulates app configuration
module App
class << self
def env
ENV['RACK_ENV'] || 'development'
end
def root
Pathname.new(File.expand_path('..', __dir__))
end
end
end
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/config/unicorn.rb | app/config/unicorn.rb | # frozen_string_literal: true
worker_process_count = (ENV['WORKER_PROCESSES'] || 4).to_i
preload_app true
worker_processes worker_process_count
timeout 10
before_fork do |_, _|
Sequel::DATABASES.each(&:disconnect)
end
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/app/config/initializers/sequel.rb | app/config/initializers/sequel.rb | # frozen_string_literal: true
require 'pg'
require 'sequel'
Sequel.single_threaded = true
Sequel.connect(ENV['DATABASE_URL'] || "postgres://localhost/fixer_#{App.env}")
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/gem/spec/fixer_spec.rb | gem/spec/fixer_spec.rb | # frozen_string_literal: true
require_relative 'helper'
describe Fixer do
before do
@mock = MiniTest::Mock.new
end
after do
@mock.verify
end
it 'returns current rates' do
@mock.expect(:call, nil, [:current])
Fixer::Feed.stub(:new, @mock) do
Fixer.current
end
end
it 'returns ... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/gem/spec/helper.rb | gem/spec/helper.rb | # frozen_string_literal: true
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'minitest/autorun'
require 'vcr'
require 'webmock'
require 'fixer'
VCR.configure do |c|
c.cassette_library_dir = 'spec/vcr_cassettes'
c.hook_into :webmock
end
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/gem/spec/fixer/feed_spec.rb | gem/spec/fixer/feed_spec.rb | # frozen_string_literal: true
require_relative '../helper'
module Fixer
describe Feed do
before { VCR.insert_cassette 'fixer' }
after { VCR.eject_cassette }
it 'parses the date of a currency' do
feed = Feed.new(:current)
currency = feed.first
currency[:date].must_be_kind_of Date
... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/gem/lib/fixer.rb | gem/lib/fixer.rb | # frozen_string_literal: true
require 'fixer/feed'
# ECB exchange rate datasets
#
# The three available short hands here are `.current`, `.ninety_days`, and
# `.historical`.
module Fixer
class << self
Feed::SCOPES.each_key do |scope|
define_method(scope) do
Feed.new(scope)
end
end
end
... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/gem/lib/fixer/feed.rb | gem/lib/fixer/feed.rb | # frozen_string_literal: true
require 'net/http'
require 'rexml/document'
module Fixer
# Wraps ECB's data feed
class Feed
include Enumerable
SCOPES = {
current: 'daily',
ninety_days: 'hist-90d',
historical: 'hist'
}.freeze
def initialize(scope = :current)
@scope = SCOPES.... | ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
fixerAPI/fixer | https://github.com/fixerAPI/fixer/blob/f090c3803015c523238ef6e633acd2bee474db04/gem/lib/fixer/version.rb | gem/lib/fixer/version.rb | # frozen_string_literal: true
module Fixer
VERSION = '1.0.0'
end
| ruby | MIT | f090c3803015c523238ef6e633acd2bee474db04 | 2026-01-04T15:54:30.063394Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/hardware.rb | Library/Homebrew/hardware.rb | module Hardware
class CPU
INTEL_32BIT_ARCHS = [:i386].freeze
INTEL_64BIT_ARCHS = [:x86_64].freeze
PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze
PPC_64BIT_ARCHS = [:ppc64].freeze
class << self
OPTIMIZATION_FLAGS = {
native: "-march=native",
nehalem... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/test.rb | Library/Homebrew/test.rb | old_trap = trap("INT") { exit! 130 }
require "global"
require "extend/ENV"
require "timeout"
require "debrew"
require "formula_assertions"
require "fcntl"
require "socket"
TEST_TIMEOUT_SECONDS = 5 * 60
begin
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcnt... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/brew.rb | Library/Homebrew/brew.rb | unless ENV["HOMEBREW_BREW_FILE"]
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!"
end
std_trap = trap("INT") { exit! 130 } # no backtrace thanks
# check ruby version before requiring any modules.
RUBY_X, RUBY_Y, = RUBY_VERSION.split(".").map(&:to_i)
if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/resource.rb | Library/Homebrew/resource.rb | require "download_strategy"
require "checksum"
require "version"
require "mktemp"
# Resource is the fundamental representation of an external resource. The
# primary formula download, along with other declared resources, are instances
# of this class.
class Resource
include FileUtils
attr_reader :mirrors, :specs,... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/readall.rb | Library/Homebrew/readall.rb | require "formula"
module Readall
class << self
def valid_ruby_syntax?(ruby_files)
ruby_files_queue = Queue.new
ruby_files.each { |f| ruby_files_queue << f }
failed = false
workers = (0...Hardware::CPU.cores).map do
Thread.new do
Kernel.loop do
begin
... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/unpack_strategy.rb | Library/Homebrew/unpack_strategy.rb | module UnpackStrategy
module Magic
# length of the longest regex (currently Tar)
MAX_MAGIC_NUMBER_LENGTH = 262
refine Pathname do
def magic_number
@magic_number ||= if directory?
""
else
binread(MAX_MAGIC_NUMBER_LENGTH) || ""
end
end
def file... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/formula_pin.rb | Library/Homebrew/formula_pin.rb | require "keg"
class FormulaPin
def initialize(f)
@f = f
end
def path
HOMEBREW_PINNED_KEGS/@f.name
end
def pin_at(version)
HOMEBREW_PINNED_KEGS.mkpath
version_path = @f.rack/version
path.make_relative_symlink(version_path) unless pinned? || !version_path.exist?
end
def pin
pin_a... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/metafiles.rb | Library/Homebrew/metafiles.rb | module Metafiles
# https://github.com/github/markup#markups
EXTENSIONS = Set.new %w[
.adoc .asc .asciidoc .creole .html .markdown .md .mdown .mediawiki .mkdn
.org .pod .rdoc .rst .rtf .textile .txt .wiki
].freeze
BASENAMES = Set.new %w[
about authors changelog changes copying copyright history licen... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/sandbox.rb | Library/Homebrew/sandbox.rb | require "erb"
require "tempfile"
class Sandbox
SANDBOX_EXEC = "/usr/bin/sandbox-exec".freeze
def self.available?
OS.mac? && OS::Mac.version >= "10.6" && File.executable?(SANDBOX_EXEC)
end
def self.formula?(_formula)
return false unless available?
!ARGV.no_sandbox?
end
def self.test?
ret... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/formula_versions.rb | Library/Homebrew/formula_versions.rb | require "formula"
class FormulaVersions
IGNORED_EXCEPTIONS = [
ArgumentError, NameError, SyntaxError, TypeError,
FormulaSpecificationError, FormulaValidationError,
ErrorDuringExecution, LoadError, MethodDeprecatedError
].freeze
MAX_VERSIONS_DEPTH = 2
attr_reader :name, :path, :repository, :entry_... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/cache_store.rb | Library/Homebrew/cache_store.rb | require "json"
#
# `CacheStoreDatabase` acts as an interface to a persistent storage mechanism
# residing in the `HOMEBREW_CACHE`.
#
class CacheStoreDatabase
# Yields the cache store database.
# Closes the database after use if it has been loaded.
#
# @param [Symbol] type
# @yield [CacheStoreDatabase] self... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/system_command.rb | Library/Homebrew/system_command.rb | require "open3"
require "ostruct"
require "plist"
require "shellwords"
require "extend/io"
require "extend/hash_validator"
using HashValidator
require "extend/predicable"
module Kernel
def system_command(*args)
SystemCommand.run(*args)
end
def system_command!(*args)
SystemCommand.run!(*args)
end
end
... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/version.rb | Library/Homebrew/version.rb | require "version/null"
class Version
include Comparable
def self.formula_optionally_versioned_regex(name, full: true)
/#{"^" if full}#{Regexp.escape(name)}(@\d[\d.]*)?#{"$" if full}/
end
class Token
include Comparable
attr_reader :value
def initialize(value)
@value = value
end
... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/exceptions.rb | Library/Homebrew/exceptions.rb | require "shellwords"
class UsageError < RuntimeError
attr_reader :reason
def initialize(reason = nil)
@reason = reason
end
def to_s
s = "Invalid usage"
s += ": #{reason}" if reason
s
end
end
class FormulaUnspecifiedError < UsageError
def initialize
super "This command requires a form... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/requirement.rb | Library/Homebrew/requirement.rb | require "dependable"
require "dependency"
require "dependencies"
require "build_environment"
# A base class for non-formula requirements needed by formulae.
# A "fatal" requirement is one that will fail the build if it is not present.
# By default, Requirements are non-fatal.
class Requirement
include Dependable
... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/checksum.rb | Library/Homebrew/checksum.rb | class Checksum
extend Forwardable
attr_reader :hash_type, :hexdigest
TYPES = [:sha256].freeze
def initialize(hash_type, hexdigest)
@hash_type = hash_type
@hexdigest = hexdigest
end
delegate [:empty?, :to_s] => :@hexdigest
def ==(other)
hash_type == other&.hash_type && hexdigest == other.h... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/keg_relocate.rb | Library/Homebrew/keg_relocate.rb | class Keg
PREFIX_PLACEHOLDER = "@@HOMEBREW_PREFIX@@".freeze
CELLAR_PLACEHOLDER = "@@HOMEBREW_CELLAR@@".freeze
REPOSITORY_PLACEHOLDER = "@@HOMEBREW_REPOSITORY@@".freeze
Relocation = Struct.new(:old_prefix, :old_cellar, :old_repository,
:new_prefix, :new_cellar, :new_repository) do
... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/searchable.rb | Library/Homebrew/searchable.rb | module Searchable
def search(string_or_regex, &block)
case string_or_regex
when Regexp
search_regex(string_or_regex, &block)
else
search_string(string_or_regex.to_str, &block)
end
end
private
def simplify_string(string)
string.downcase.gsub(/[^a-z\d]/i, "")
end
def search_... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/reinstall.rb | Library/Homebrew/reinstall.rb | require "formula_installer"
require "development_tools"
require "messages"
module Homebrew
module_function
def reinstall_formula(f, build_from_source: false)
if f.opt_prefix.directory?
keg = Keg.new(f.opt_prefix.resolved_path)
keg_had_linked_opt = true
keg_was_linked = keg.linked?
back... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/build.rb | Library/Homebrew/build.rb | # This script is loaded by formula_installer as a separate instance.
# Thrown exceptions are propagated back to the parent process over a pipe
old_trap = trap("INT") { exit! 130 }
require "global"
require "build_options"
require "cxxstdlib"
require "keg"
require "extend/ENV"
require "debrew"
require "fcntl"
require "... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/description_cache_store.rb | Library/Homebrew/description_cache_store.rb | require "set"
require "cache_store"
require "searchable"
#
# `DescriptionCacheStore` provides methods to fetch and mutate linkage-specific data used
# by the `brew linkage` command.
#
class DescriptionCacheStore < CacheStore
include Searchable
# Inserts a formula description into the cache if it does not exist or... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/cleanup.rb | Library/Homebrew/cleanup.rb | require "utils/bottles"
require "formula"
require "cask/cask_loader"
require "set"
CLEANUP_DEFAULT_DAYS = 30
CLEANUP_MAX_AGE_DAYS = 120
module CleanupRefinement
refine Enumerator do
def parallel
queue = Queue.new
each do |element|
queue.enq(element)
end
workers = (0...Hardware:... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/options.rb | Library/Homebrew/options.rb | class Option
attr_reader :name, :description, :flag
def initialize(name, description = "")
@name = name
@flag = "--#{name}"
@description = description
end
def to_s
flag
end
def <=>(other)
return unless other.is_a?(Option)
name <=> other.name
end
def ==(other)
instance_of... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/missing_formula.rb | Library/Homebrew/missing_formula.rb | require "formulary"
module Homebrew
module MissingFormula
class << self
def reason(name, silent: false)
blacklisted_reason(name) || tap_migration_reason(name) ||
deleted_reason(name, silent: silent)
end
def blacklisted_reason(name)
case name.downcase
when "gem... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Linuxbrew/brew | https://github.com/Linuxbrew/brew/blob/93389fde63974f096156344e281610acec44130c/Library/Homebrew/caveats.rb | Library/Homebrew/caveats.rb | require "language/python"
class Caveats
extend Forwardable
attr_reader :f
def initialize(f)
@f = f
end
def caveats
caveats = []
begin
build = f.build
f.build = Tab.for_formula(f)
s = f.caveats.to_s
caveats << s.chomp + "\n" unless s.empty?
ensure
f.build = bui... | ruby | BSD-2-Clause | 93389fde63974f096156344e281610acec44130c | 2026-01-04T15:53:38.399858Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.