Skip to content

Instantly share code, notes, and snippets.

@s-ashwinkumar
Last active August 15, 2017 05:49
Show Gist options
  • Save s-ashwinkumar/70decb8711f55c8b5523f711484d616c to your computer and use it in GitHub Desktop.
Save s-ashwinkumar/70decb8711f55c8b5523f711484d616c to your computer and use it in GitHub Desktop.

Revisions

  1. s-ashwinkumar revised this gist Aug 15, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions methodMissingDeprecation.rb
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ def new_method2

    def method_missing(name, *args, &block)
    super unless @@old_methods.keys.include?(name.to_sym)
    warn "#{name} will be deprecated with next release dated 09/01/2017"
    warn "WARNING : #{name} will be deprecated with next release dated 09/01/2017"
    send(@@old_methods[name.to_sym])
    end

    @@ -21,12 +21,12 @@ def method_missing(name, *args, &block)
    obj = Myclass.new
    # => #<Myclass:0x0000000271c288>
    obj.oldMethod1
    #oldMethod1 will be deprecated with next release dated 09/01/2017
    #WARNING : oldMethod1 will be deprecated with next release dated 09/01/2017
    # => "Myclass#new_method1"
    obj.new_method1
    # =>"Myclass#new_method1"
    obj.oldMethod2
    #oldMethod2 will be deprecated with next release dated 09/01/2017
    #WARNING : oldMethod2 will be deprecated with next release dated 09/01/2017
    # => "Myclass#new_method2"
    obj.non_existant_method
    #NoMethodError: undefined method `non_existant_method' for #<Myclass:0x0000000271c288>
  2. s-ashwinkumar revised this gist Aug 15, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions methodMissingDeprecation.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    class Myclass
    @@old_methods = { old_method1: :new_method1, old_method2: :new_method2 }
    @@old_methods = { oldMethod1: :new_method1, oldMethod2: :new_method2 }

    def new_method1
    'Myclass#new_method1'
    @@ -20,13 +20,13 @@ def method_missing(name, *args, &block)

    obj = Myclass.new
    # => #<Myclass:0x0000000271c288>
    obj.old_method1
    #old_method1 will be deprecated with next release dated 09/01/2017
    obj.oldMethod1
    #oldMethod1 will be deprecated with next release dated 09/01/2017
    # => "Myclass#new_method1"
    obj.new_method1
    # =>"Myclass#new_method1"
    obj.old_method2
    #old_method2 will be deprecated with next release dated 09/01/2017
    obj.oldMethod2
    #oldMethod2 will be deprecated with next release dated 09/01/2017
    # => "Myclass#new_method2"
    obj.non_existant_method
    #NoMethodError: undefined method `non_existant_method' for #<Myclass:0x0000000271c288>
  3. s-ashwinkumar revised this gist Aug 15, 2017. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions methodMissingDeprecation.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    class Myclass
    @@old_methods = {:old_mehod1 old_method2)
    @@old_methods = { old_method1: :new_method1, old_method2: :new_method2 }

    def new_method1
    'Myclass#new_method1'
    @@ -10,13 +10,14 @@ def new_method2
    end

    def method_missing(name, *args, &block)
    super unless @@old_methods.include?(name)
    super unless @@old_methods.keys.include?(name.to_sym)
    warn "#{name} will be deprecated with next release dated 09/01/2017"
    send(name.to_sym)
    send(@@old_methods[name.to_sym])
    end

    end


    obj = Myclass.new
    # => #<Myclass:0x0000000271c288>
    obj.old_method1
  4. s-ashwinkumar revised this gist Aug 15, 2017. No changes.
  5. s-ashwinkumar revised this gist Aug 15, 2017. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions testin.rb
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    class Myclass
    end
  6. s-ashwinkumar created this gist Aug 15, 2017.
    31 changes: 31 additions & 0 deletions methodMissingDeprecation.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    class Myclass
    @@old_methods = {:old_mehod1 old_method2)

    def new_method1
    'Myclass#new_method1'
    end

    def new_method2
    'Myclass#new_method2'
    end

    def method_missing(name, *args, &block)
    super unless @@old_methods.include?(name)
    warn "#{name} will be deprecated with next release dated 09/01/2017"
    send(name.to_sym)
    end

    end

    obj = Myclass.new
    # => #<Myclass:0x0000000271c288>
    obj.old_method1
    #old_method1 will be deprecated with next release dated 09/01/2017
    # => "Myclass#new_method1"
    obj.new_method1
    # =>"Myclass#new_method1"
    obj.old_method2
    #old_method2 will be deprecated with next release dated 09/01/2017
    # => "Myclass#new_method2"
    obj.non_existant_method
    #NoMethodError: undefined method `non_existant_method' for #<Myclass:0x0000000271c288>
    2 changes: 2 additions & 0 deletions testin.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    class Myclass
    end