Skip to content

Instantly share code, notes, and snippets.

@yoelblum
yoelblum / ruby_inheritance.rb
Last active October 18, 2023 01:44
Ruby base class VS including modules (mixins)
# Ruby's inheritance mechanisms are a bit unique and have some subtelties
# There are two main ways to inherit: Direct Inheritance (with a "Base" class) and "Mixins" (including modules)
# "Direct inheritance" (B is the base class of A)
class B
X = 30
def self.static_method
"Hello from static method"
end
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
@yoelblum
yoelblum / gist:1b1c42ca33b199d08a4e44563010c51c
Last active April 18, 2018 13:24
Leaseweb Ruby Secure URL
def leaseweb_secure_url
cname = 'your.cdn.name'
path = path_to_file
secret = 'YourSecret'
expire = (Time.now.to_i + 86400).to_s
ip = ''
secure_url = secret + ip + path + expire
secure_url_md5 = Digest::MD5.digest(secure_url)
secure_url_base64 = Base64.strict_encode64(secure_url_md5)
secure_url_base64 = secure_url_base64.gsub('+', '-').gsub('/', '_')