Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie Lawrence ideasasylum

View GitHub Profile
@peterc
peterc / methods_returning.rb
Last active Jun 19, 2021
Object#methods_returning - to work out which method on an object returns what we want
View methods_returning.rb
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@manuelmeurer
manuelmeurer / controller.rb
Last active Nov 15, 2016
Render dynamic CSS
View controller.rb
class Display::WidgetsController < ApplicationController
def show
scss = render_to_string('show', locals: { foo: bar }, formats: :scss)
@css = Sass::Engine.new(scss, Compass.sass_engine_options.merge(syntax: :scss)).render
end
end