在 C++ 中,我可以这样做:
(condition ? sin : cos)(0.5);
或者
typedef std::deque<int> T;
(T().*(condition ? &T::push_back : &T::push_front))(1);
在 Ruby 中,这相当于什么?
我知道我可以使用send
or method
,但它们允许我调用private
方法。
# String#puts and String#print are private
("".method condition ? :puts : :print).call