Skip to content

Instantly share code, notes, and snippets.

@apotonick
Last active November 21, 2018 07:19
Show Gist options
  • Save apotonick/2f9fe3979b7817147e05 to your computer and use it in GitHub Desktop.
Save apotonick/2f9fe3979b7817147e05 to your computer and use it in GitHub Desktop.
My Ruby Wishlist
# 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
Copy link

kaikuchn commented Jan 7, 2016

What would be the difference between line 12's module A::B::M and the proposed namespace keyword?

@headius
Copy link

headius commented Oct 26, 2016

👍

@apotonick
Copy link
Author

@kaikuchn with namespace I don't need to know if it's a class and what's it derived from.

@solnic
Copy link

solnic commented Oct 27, 2016

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

@apotonick
Copy link
Author

I know @solnic and I'm still evaluating if I should introduce that in TRB 2.

@fusillicode
Copy link

@ntl
Copy link

ntl commented Oct 27, 2016

@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