Crystal Wiki says an alternative to Ruby
alias_method is using
previous_def. From what I can see, this doesn’t do much, compared to Ruby style. I’ve used and seen
alias_method both in libraries (for deprecation support), and also in application types for execution of previous method definition (in specific cases, ie. shorthands).
alias_method is pretty simple in Ruby. Just alias to previous definition, similar to what Crystal offers (ie. in inheritance).
class User def full_name puts "Nur Yubr" end # Using `alias_method` to run previous declar alias_method :name, :full_name end User.new.name
perf_def overwrites previous method declaration, as per the Wiki. This works well if inheritance is in use. But otherwise, we can’t alias to previous method definition.
class User def full_name puts "Nur Yubr" end # doesn't make much sense to use previous_def # => previous_def # `alias` is not usable in this case # alias name = full_name # hacky alternative def name full_name end end User.new.name
Any points? @Sija pointed asking @r00ster91, maybe he can share some detail. Anyway, looking forward to see alternatives.