ruby - How to use method calls within rjust? -



ruby - How to use method calls within rjust? -

as part of ruby learning, phone call size method within rjust passing first parameter. not sure how it.

for e.g.

2.to_s(2) #=> returns "10"

now, utilize rjust on 10 passing :size + 5 first argument *****10

2.to_s(2).rjust(how_to_get_size_of_10_and_add_5, "*") #=> dont know how to.

unsuccessfully, tried below:

2.to_s(2).tap{|s| rjust(s.size+5,"*")} #=> ...undefined method `rjust' main:object 2.to_s(2).rjust(send(:size)+5,"*") #=> ... undefined method `size' main:object

i trying understand how refer , exercise method on part of chain of method calls. in illustration trying phone call rjust on 2.to_s(2) , within rjust refer size of 2.to_s(2). sorry if writing clumsy

i don't understand why doing indirectly, perhaps tried is:

2.to_s(2).tap{|s| break s.rjust(s.size + 5, "*")}

a new method proposed in ruby core situations this, not yet available. in mean while, have utilize combination of tap , break.

ruby

Comments

Popular posts from this blog

javascript - I need to update the text of a paragraph by inline edit -

javascript - THREE.js reposition vertices for RingGeometry -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -