Combinatory method like tap, but able to return a different value?

前端 未结 5 1716
时光取名叫无心
时光取名叫无心 2020-12-24 06:00

I\'m going through a phase of trying to avoid temporary variables and over-use of conditional where I can use a more fluid style of coding. I\'ve taken a great liking to us

5条回答
  •  Happy的楠姐
    2020-12-24 06:43

    I needed to do something like this and I like tokland's answer, but I didn't want to pollute Object for the small script I was writing. Instead, I made use of tap on an array:

    [something_complicated].tap { |s| s[0] = new_cool_thing)}.first
    

提交回复
热议问题