在红宝石中找到位置值

eld*_*uth 0 ruby math

我正在尝试研究这个简单的操作,而我却没有为它做任何事情.我希望能够找到一个整数的位置值,我想知道是否有特定的宝石或操作.例如:

a = 1651684651
p find_place_value_of(a,5) # imaginary function to return the value of the
                           #  number in the 10000 column
                           #  output should be 8
Run Code Online (Sandbox Code Playgroud)

到目前为止,我能做的最好的事情是想出这个丑陋的小功能:

j= 262322
a= j 
a/=100000 
b= j - a*100000
b/=10000 
c= j - a*100000 - b*10000 
c/=1000 
d= j - a*100000 - b*10000 - c*1000 
d/=100 
e= j - a*100000 - b*10000 - c*1000 - d*100
e/=10 
f= j - a*100000 - b*10000 - c*1000 - d*100 - e*10
p a,b,c,d,e,f,j
Run Code Online (Sandbox Code Playgroud)

是否有更优雅的方式来寻找地方价值?

Cha*_*ell 5

将整数转换为字符串,然后获取第n个位置的字符.

a.to_s[5] #=> '8'
Run Code Online (Sandbox Code Playgroud)