kjleitz / adornable Goto Github PK
View Code? Open in Web Editor NEWUse decorators on Ruby methods!
License: MIT License
Use decorators on Ruby methods!
License: MIT License
Is there a technical reason to separate syntax to memoize methods with or without arguments? If method accepts any arguments it doesn't make much sense to memoize the same result for different arguments. I used to use the Memoist gem. The syntax there is the same regardless if the method accepts arguments. Arguments passed to the methods are always used as a part of the cache key.
I am not sure if this qualifies as the issue per se. I guess this is a suggestion to just use one syntax for both variants. :-)
Why can't I add decortors inside singleton classes? I get that the error is saying name
isn't defined for the singleton class, but why do we need it?
require 'adornable'
class Decorators
def self.time(context, stat:, &block)
start_time = Time.now.utc
begin
return yield
ensure
end_time = Time.now.utc
duration = (end_time - start_time) * 1000.0
puts "#{stat} #{duration}ms"
end
end
end
class Dog
class << self
extend Adornable
decorate :time, from: Decorators, stat: 'bark'
def bark
sleep 1.3
end
end
end
Dog.bark
Traceback (most recent call last):
3: from adornable.rb:16:in `<main>'
2: from adornable.rb:17:in `<class:Dog>'
1: from adornable.rb:20:in `singleton class'
/Users/jaredw/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/adornable-1.2.0/lib/adornable.rb:18:in `decorate': Decorator name must be provided. (Adornable::Error::InvalidDecoratorArguments)
def decorate(decorator_name, from: nil, defer_validation: false, **decorator_options)
if Adornable::Utils.blank?(name)
raise Adornable::Error::InvalidDecoratorArguments, "Decorator name must be provided."
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.