Advertisement
terraplane

Untitled

Apr 8th, 2022
1,551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.34 KB | None | 0 0
  1. require 'spec_helper'
  2.  
  3. class C
  4.   def a
  5.     'I am a'
  6.   end
  7.  
  8.   def b
  9.     'I am b'
  10.   end
  11.  
  12.   def m(i)
  13.     methods = {
  14.       1 => :a,
  15.       2 => :b
  16.     }
  17.     send(methods[i])
  18.   end
  19. end
  20.  
  21. describe 'Name hash' do
  22.   it 'works' do
  23.     obj = C.new
  24.  
  25.     expect(obj.m(1)).to eq('I am a')
  26.     expect(obj.m(2)).to eq('I am b')
  27.   end
  28. end
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement