Ruby 学习时该有哪些需要注意的坑

ruby正则替换(sub)中的一个坑
为保证隐私把电话号码做星号替换,这种需求比较简单,一般用正则替换就可以了,但是在使用ruby实现这个需求的过程中发现一个小bug,见下面代码 irb(main):001:0 phone = = irb(main):002:0 phone.sub(/(\d{3})\d{4}(\d{4})/,#{$1}****#
为保证隐私把电话号码做星号替换,这种需求比较简单,一般用正则替换就可以了,但是在使用ruby实现这个需求的过程中发现一个小bug,见下面代码
irb(main):001:0& phone = &&
irb(main):002:0& phone.sub(/(\d{3})\d{4}(\d{4})/,&#{$1}****#{$2}&)
irb(main):003:0& phone.sub(/(\d{3})\d{4}(\d{4})/,&#{$1}****#{$2}&)
=& &155****5555&
irb(main):004:0& phone = &&
irb(main):005:0& phone.sub(/(\d{3})\d{4}(\d{4})/,&#{$1}****#{$2}&)
=& &155****5555&
irb(main):006:0& phone.sub(/(\d{3})\d{4}(\d{4})/,&#{$1}****#{$2}&)
=& &133****3333&
通过上面的代码可以看出第一次执行sub函数的时候,不会替换成功,执行一次以后才会生成$1以及$2全局变量,更换phone值后继续执行执行sub,发现$1与$2变量没有变化,执行一直滞后一步,后来在@blackanger指点下,找到了问题所在,避免这样的问题可以直接使用block代码块,确保第一次执行时候$1与$2已经生成,这样就可以保证替换工作得顺利进行。
irb(main):012:0& phone = &&
irb(main):013:0& phone.sub(/(\d{3})\d{4}(\d{4})/){&#{$1}****#{$2}&}
=& &133****3344&
你最喜欢的Andriod开发中,有哪些需要注意的坑? - testbird_程序设计-06学习网
& 浏览文章
Andriod开发中,有哪些需要注意的坑? - testbird
来源:网络编辑:佚名时间:人气:
1:Andorid L theme colorPrimary 不能使用带有alpha的颜色值,否则会有异常抛出, 直接判断了是否alpha是否等于0或者255,其他都会异常。
protected void onApplyThemeResource(Resources.Theme theme, int resid,
boolean first) {
if (mParent == null) {
super.onApplyThemeResource(theme, resid, first);
theme.setTo(mParent.getTheme());
} catch (Exception e) {
theme.applyStyle(resid, false);
// Get the primary color and update the TaskDescription for this activity
if (theme != null) {
TypedArray a = theme.obtainStyledAttributes(com.android.internal.R.styleable.Theme);
int colorPrimary = a.getColor(com.android.internal.R.styleable.Theme_colorPrimary, 0);
a.recycle();
if (colorPrimary != 0) {
ActivityManager.TaskDescription v = new ActivityManager.TaskDescription(null, null,
colorPrimary);
setTaskDescription(v);
* Creates the TaskDescription to the specified values.
* @param label A label and description of the current state of this task.
* @param icon An icon that represents the current state of this task.
* @param colorPrimary A color to override the theme's primary color. This color must be opaque.
public TaskDescription(String label, Bitmap icon, int colorPrimary) {
if ((colorPrimary != 0) && (Color.alpha(colorPrimary) != 255)) {
throw new RuntimeException("A TaskDescription's primary color should be opaque");
mColorPrimary = colorP
2:android 5.0花屏,由于过度绘制导致,关闭硬件加速。3:华为的受保护应用问题,华为有自己的一套连接机制,时间一长就把网络给切断掉。4:相同颜色值在全局是同一份,如果对其改变获取后的colorDrawable值,会导致其它所有使用的地方都改变,可以采用mutable避免。5:华为p8手机,如果service与ui不在同一进程,service中监控网络的BroadcastReciver 收不到网络连上的广播,但是能收到断开的广播。6:建议做手游或者app测试时使用第三方测试平台,比如像Testbird云测平台(现在注册送免费调试时间)之类的,方便快捷,且结论更准确。
在sipp脚本编写中,通常遇到branch分支的情况,需要进行跳转时,都会用到next命令,通过next命令可以随意跳转到下一个指定的label位置。但是next命令存在局限性,那就是不能向当前位置之前的标签进行跳转,这就导致了很多条件判断需要重复操作的流程无法进行。其实在sipp中还定义了另一个实用的命令,那就是jump。
在使用sipp脚本对sipserver和AS进行相关业务测试时,转接业务是较为复杂的业务流程类型,尤其是其中UE2涉及到两方呼叫流程的交互作用,对于构造sipp脚本而言更加繁琐。如下是我在日常工作中调试通过的sipp脚本内容,能够较好地模拟出盲转业务流程,可供大家参考。脚本未经过梳理,里面存在较多调试过程所涉及到的变量,请注意。
热门文章排行
浏览 1292浏览 1230浏览 1145浏览 1083<a href="/program/programnews/news/264742.htm" target="_blank" title="浏览 1028浏览 826浏览 735浏览 664浏览 648浏览 604分享给朋友:把视频贴到Blog或BBS&&通用代码: <input id="link4" type="text" class="form_input form_input_s" value="" />复 制flash地址: 复 制html代码: <input type="text" class="form_input form_input_s" id="link3" value="" />复 制分享视频到站外获取收益&&手机扫码分享视频二维码2小时内有效ruby读取midi(midilib)并用winmm播放的坑下载至电脑扫码用手机看用或微信扫码在手机上继续观看二维码2小时内有效ruby读取midi(midilib)并用winmm播放的坑扫码用手机继续看用或微信扫码在手机上继续观看二维码2小时内有效,扫码后可分享给好友没有优酷APP?立即下载请根据您的设备选择下载版本
药品服务许可证(京)-经营-
节目制作经营许可证京字670号
请使用者仔细阅读优酷、、
Copyright(C)2017 优酷
不良信息举报电话:

我要回帖

 

随机推荐