Last active
November 21, 2018 07:19
-
-
Save apotonick/2f9fe3979b7817147e05 to your computer and use it in GitHub Desktop.
My Ruby Wishlist
This file contains 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
# Ruby Wishlist | |
## Removals | |
* finalize! method for classes | |
* Remove constant_finding/loading at runtime, it always breaks. | |
## Module.freeze | |
Remove the ability to dynamically change code at runtime | |
```ruby | |
module A | |
# .. | |
def b | |
@b = "hello" # this breaks | |
end | |
end.freeze | |
``` | |
this is obviously only for "functional module" usage of `A`. | |
## Remove all bang methods | |
merge! | |
## Implicit Boolean | |
result = Result.new(valid: true) | |
if result ... # the if should call result.to_bool | |
## wrong constant | |
# when referencing `A::B`, don't simply assume that I might've been meaning `::B` but throw a fucking exception and don't trick me. | |
## Procs without context (faster than procs with context and probably method calls) | |
function(*) {} | |
# as discussed here: https://twitter.com/headius/status/791377081347088384 | |
## Namespace | |
class A | |
class B < A | |
end | |
end | |
# i can now do | |
module A::B::M | |
end | |
# but that would be great: | |
namespace A::B # i don't have to know if this is a class, or module, what the superclass is, and so on. | |
module M | |
end | |
end | |
# i know that this works, but it sucks | |
A::B.class_eval do | |
module M | |
end | |
end | |
## Instance Variable Arguments | |
def (@options={}) | |
## pass more options to ::included | |
include Module, awesome: true | |
module Module | |
def self.included(base, options) | |
end | |
## Immutable "methods" | |
imdef something(a, b) | |
# when calling something all args are automatically immutable |
👍
@kaikuchn with namespace
I don't need to know if it's a class and what's it derived from.
pass more options to included
This is exactly why I started using module-subclassing ie include Foo.new(options)
where Foo
is a Module
subclass
I know @solnic and I'm still evaluating if I should introduce that in TRB 2.
This would be really awesome! Coffee like! ;) https://gist.github.com/apotonick/2f9fe3979b7817147e05#file-wishlist-rb-L38
@solnic in my experience, the downside of inheriting from Module is that the ensuing code is typically very difficult to understand. All the instance methods have to get grafted on via metaprogramming instead of just defining them in the module. I'd love to have include
accept a few named params.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What would be the difference between line 12's
module A::B::M
and the proposed namespace keyword?