Questions tagged [alias-method]

32 questions
3
votes
1 answer

alias_method, alias_method_chain, and self.included

I'm having a little difficulty understanding alias_method/alias_method_chain. I have the following code: module ActionView::Helpers module FormHelper alias_method :form_for_without_cherries, :form_for def form_for(record, options = {},…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
2
votes
1 answer

ruby method_alias in inherited class

I'm deeping into ruby metaprogramming and have next question. Example: module ExampleAliaser def do_example_alias(prefix=:origin) class_eval <<-EOS class << self alias_method :#{prefix}_example, :example def…
Fivell
  • 11,829
  • 3
  • 61
  • 99
2
votes
3 answers

OO-Perl Aliasing Class Attributes

I have a module that I'm working on. I am setting up a few attributes like this: $self->{FOO}; $self->{BAR}; $self->{FOOBAR}; And, I want to use AUTOLOAD to help create methods for accessing these attributes. For example, $foo->Bar() returns the…
David W.
  • 281
  • 2
  • 4
2
votes
1 answer

ruby alias_method in class method

It seems that alias_method doesn't work the same way inside a class << self block as it does outside. Specifically, when I use alias_method for an instance method and subsequently override the method, the alias name can be used to access the…
Andrew Schwartz
  • 4,440
  • 3
  • 25
  • 58
2
votes
1 answer

alias_attribute and creating and method with the original attribute name causes a loop

Im trying to dynamically create a method chain in one attribute in my model. By now I have this function: def create_filtered_attribute(attribute_name) alias_attribute "#{attribute_name}_without_filter", attribute_name …
Tiago
  • 2,966
  • 4
  • 33
  • 41
2
votes
1 answer

Is it possible to alias to_s?

Instead of overriding to_s in my model I'd like to alias it to an existing method called full_name. Both alias and alias_method don't seem to work as expected. Using alias class Person < ActiveRecord::Base # ... other model code. alias to_s…
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
2
votes
2 answers

ruby on rails add functionality to model property change

In my rails model, I have a decimal property called employer_wcb. I would like it if, when employer_wcb was changed, a dirty bit was set to true. I'd like to override the employer_wcb setter method. Any way to do so (in particular using…
Daniel
  • 16,026
  • 18
  • 65
  • 89
1
vote
1 answer

class << self, alias_method, and monkey patching Mechanize::Cookie

I have an issue with Mechanize::Cookie misbehaving and I want to trying to monkey patch it. My code: class Mechanize::Cookie class << self; alias_method :old_parse, :parse end def self.parse(uri, str, log = Mechanize.log) puts 'new parse!' …
pguardiario
  • 53,827
  • 19
  • 119
  • 159
1
vote
2 answers

Improving on hacky ruby 'method_alias' fix for conflicting redmine plugins?

Using redmine 3.x, I have a dependency conflict between two plugins - redmine subtask list accordion and Subtask list inherited fields. Installing both raises 500 errors when trying to view an issue. ActionView::Template::Error (undefined method…
Ben S
  • 95
  • 1
  • 7
1
vote
2 answers

When should I use an Alias Method? - Ruby

I've looked through and haven't seen an answer to: What would you use an alias method? class Vampire attr_reader :name, :thirsty alias_method :thirsty?, :thirsty end Is the only reason I would use one is to be able to use a question mark with…
mph85
  • 1,276
  • 4
  • 19
  • 39
1
vote
1 answer

Add alias to logical operators

I have ruby project (without rails) and i want to add aliases to the logical AND and OR operators for my class. I have already overloaded logical operators for my class, but if I add alias_method :foo, :or and use like class_example_1 foo…
0
votes
1 answer

undefined method for model class that I want no modify by alias_method

I tried to path the ActiveRecord model validation - require_dependency "issue" module IssuePath def self.included(base) # :nodoc: base.send(:include, InstanceMethods) base.class_eval do alias_method :strict_validate_issue,…
0
votes
0 answers

Rails Monkey Patch alias_method cause no method error

I am trying to monkey patch rails Rails.cache.fetch/read method, and add my extra log on every fetch/read happened, but i got some other error that i can't google any answer. here is my monkey patch code module ActiveSupport module Cache …
Wallace
  • 151
  • 1
  • 9
0
votes
1 answer

ruby self.inherited alias_method

class Base def sam "I m the base" end def self.inherited(base) alias_method :old_sam, :sam base.class_eval do def sam old_sam p "Inside inherited" end end super end end class Derived < Base …
Subin
  • 33
  • 4
0
votes
1 answer

How to access 'layout' of parent controller?

In one of my controllers I want to change the layout given some condition, and otherwise keep the default layout used by the parent ApplicationController (was "application" initially, but I'm trying some others now). Tried accessing the "layout"…
shaimo
  • 376
  • 3
  • 17